Skip to content

Instantly share code, notes, and snippets.

@rros
Last active August 12, 2016 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rros/99e48cf452e1c798ec3a71fae5fd490e to your computer and use it in GitHub Desktop.
Save rros/99e48cf452e1c798ec3a71fae5fd490e to your computer and use it in GitHub Desktop.
protected async Task NavigationPopToRootAsync()
{
// Popping pages only makes sense if there are at least 2 pages on the stack.
if (this.Navigation.NavigationStack.Count < 2)
{
return;
}
// Workaround for the issue in Xamarin.Form on Windows Phone when calling PopToRootAsync()
// see: https://bugzilla.xamarin.com/show_bug.cgi?id=43298
if (Device.OS == TargetPlatform.WinPhone)
{
// First remove the pagesfrom the stack between the root page and the current page.
// Note: Make sure to call ToList() because removing pages will modify the NavigationStack collection.
foreach (var page in this.Navigation.NavigationStack.Skip(1).TakeWhile(p => p != this).ToList())
{
this.Navigation.RemovePage(page);
}
// Popping the current page will load the root page again.
await this.Navigation.PopAsync(false);
}
else
{
await this.Navigation.PopToRootAsync(false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment