Last active
August 12, 2016 11:01
-
-
Save rros/99e48cf452e1c798ec3a71fae5fd490e to your computer and use it in GitHub Desktop.
Workaround for https://bugzilla.xamarin.com/show_bug.cgi?id=43298
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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