In an Windows Phone 7 application I got a CurrentPage, which, on a special event does navigate to a new page using the NavigationService:
NavigationService.Navigate(new Uri("/NewPage.xaml", UriKind.Relative));
Now when the user clicks back on the NewPage I want the app to skip the CurrentPage and go directly to the MainPage of the app.
I tried to use NavigationService.RemoveBackEntry, but this removes the MainPage instead of the CurrentPage.
How do I navigate to a new page without putting the current on the back stack?
But you can set "automaticallyLeadingImplied: false" in the AppBar of the Scaffold you are navigating to.
When navigating to the NewPage.xaml pass along a parameter so you know when to remove the previous page from the backstack.
You can do this as such:
When navigating from CurrentPage.xaml to NewPage.xaml pass along parameter
bool remove = true; String removeParam = remove ? bool.TrueString : bool.FalseString; NavigationService.Navigate(new Uri("/NewPage.xaml?removePrevious="+removeParam , UriKind.Relative));
In the OnNavigatedTo event of NewPage.xaml, check whether to remove the previous page or not.
bool remove = false; if (NavigationContext.QueryString.ContainsKey("removePrevious")) { remove = ((string)NavigationContext.QueryString["removePrevious"]).Equals(bool.TrueString); NavigationContext.QueryString.Remove("removePrevious"); } if(remove) { NavigationService.RemoveBackEntry(); }
This way, you can decide on the CurrentPage.xaml if you want to remove it from the backstack.
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