When switching to NewPage.xaml, go through the parameter so that you know when to remove the previous page from the back.
You can do it as such:
When switching from CurrentPage.xaml to NewPage.xaml, execute the parameter
bool remove = true;
String removeParam = remove? bool.TrueString: bool.FalseString;
NavigationService.Navigate (new Uri ("/ NewPage.xaml? RemovePrevious =" + removeParam, UriKind.Relative));
In the OnNavigatedTo NewPage.xaml event, check whether to delete 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 ();
}
So you can select CurrentPage.xaml if you want to remove it from backstack.
source share