Using NavigationService.RemoveBackEntry()
I can remove one entry from the navigation stack. Is there a convenient way to remove all back navigation items in my app (scenario: I have a sign-up procedure which consists of multiple pages, and after successful registration I do not want the user to navigate back to the registration steps).
When content is navigated to, NavigationService records the navigation as an entry in navigation history. An entry is added to back navigation history when either a new navigation occurs, by calling the Navigate method, or by navigating to an entry in forward navigation history, by calling GoForward.
Also, the most recent entry in back navigation history can be removed by calling RemoveBackEntry. By default, NavigationService does not store an instance of a content object in navigation history. Instead, NavigationService creates a new instance of the content object each time it is navigated to by using navigation history.
The most recent JournalEntry in back navigation history, if there is one. If two or more navigators ( NavigationWindow, Frame) share the same navigation history, one navigator can use RemoveBackEntry to retrieve the back navigation history entry for a navigation that took place in another navigator.
By default, NavigationService does not store an instance of a content object in navigation history. Instead, NavigationService creates a new instance of the content object each time it is navigated to by using navigation history.
It's not that inconvenient to do that with RemoveBackEntry
:
while(NavigationService.CanGoBack)
{
NavigationService.RemoveBackEntry();
}
Or use this, a single line code
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
while (NavigationService.RemoveBackEntry() != null) ;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With