Live Chat Icon For mobile
Live Chat Icon

WPF FAQ - Navigation

Find answers for the most frequently asked questions
Expand All Collapse All

In most of the web based applications, there is a need to pass data between pages in order to perform specific tasks. Data can be passed between pages in the NavigationWindow using the overloads of the ‘Navigate()’ method in the ‘NavigationService’ class.

The following code snippet is used to pass data from one page to another.


mypage newpage = new mypage();
window1.NavigationService.Navigate(newpage, empid);

For this to work, mypage class should contain a constructor defined as follows.


public mypage(string empid)

Back and Forward button click can be handled using the ‘CommandBindings’ property of the ‘NavigationWindows’ class.

The following code snippet is used to handle the ’Back’ button click in a NavigationWindow.


//after InitializeComponent()
navwindow1.CommandBindings.Add(new CommandBinding(NavigationCommands.BrowseForward, OnBrowseForward));

void OnBrowseBack(object sender, ExecutedRoutedEventArgs args)
MessageBox.Show('Back Button is Clicked');


NavigationWindow is a window with the ability to navigate between pages. NavigationWindow is one of the navigators in WPF, the other being the Frame. A navigator is the one which supports navigation and navigation history. The highlight of a NavigationWindow is that it can have it’s content as any of the .NET Framework 3.0 objects or HTML contents. ‘Source’ property of the NavigationWindow can be used to set the content of the NavigationWindow.


<NavigationWindow x:Class='SampleTest.Window1'
    Height='300' Width='300' Source=''>


Share with

Couldn't find the FAQs you're looking for?

Please submit your question and answer.