Search code examples
c#wpfnavigationservice

NavigationUI Functionality in Custom Button


By default I have hidden a pages UI navigation bar using;

ShowsNavigationUI="False">

I would like to have two custom buttons that are outside of the page and in the window that implement the navigation of backwards and forwards but not using the buttons that come with the NavigationUI.

Is there a way I can use the NavigationService in WPF to move backwards without specifying a page? For example currently I use;

NavigationService.Navigate(new Uri(@"View/HRSystem/HRSystem.xaml", UriKind.Relative));

to move between pages. Effectively what I would like for a back button click action (in pseudo) is;

NavigationService.Navigate(new Uri("LastPageVisited", UriKind.Relative));

I am unsure of how to define last page visited. For further explanation I have this image;

enter image description here

The common area is where I would like to have the two custom buttons, this stays the same throughout the program. The page is what changes and what I would like to navigate between.


Solution

  • You can use the built in GoBack() and GoForward() methods.

    For example:

    NavigationService.GoBack();
    

    You should read through the methods in NavigationService on MSDN. For example, you may need to check CanGoBack to enable/disable the back button.