Sunday, June 8, 2014

Clearing backstack in NavigationService

You can use NavigationService.RemoveBackEntry:
For instance, to remove all entries from the stack:
while (this.NavigationService.BackStack.Any())
{
   this.NavigationService.RemoveBackEntry();
}

Also, if you want to remove only the previous page after checking its URI:
var previousPage = this.NavigationService.BackStack.FirstOrDefault();

if (previousPage != null && previousPage.Source.ToString().StartsWith("/MainPage.xaml"))
{
    this.NavigationService.RemoveBackEntry();
}

No comments:

Post a Comment