Detect backward event

how to determine when the back button is pressed for navigation, and divert this event to something extra. I am thinking about managing page state.

0
c # wpf
source share
2 answers

Add a handler for NavigationWindow.Navigating or NavigationService.Navigating . In your handler:

 void NavigationService_Navigating(object sender, NavigatingCancelEventArgs e) { if (e.NavigationMode == NavigationMode.Back) { e.Cancel = true; // TODO: whatever state management you're going to do } } 

NavigatingCancelEventArgs contains all the information about the navigation request that you need to control the state of the page.

+3
source share

NavigationService provides a series of events that you can subscribe to if you want to control the navigation process:

  • Navigation when the frame is about to move. Set Cancel to true to stop.
  • Navigation when navigation is finished, but before it is rendered
  • NavigationFailed when something goes wrong.
  • NavigationProgress when the pieces of a remote navigation call are downloaded.
  • NavigationStopped when the StopLoading method is called or when loading a new navigation request is executed.
  • LoadCompleted when the page was displayed
+1
source share

All Articles