Reputation: 710
I'm using Xamarin Forms and I am trying to back out of the nav stack from a button command - and navigate to a new page (essentially, I want to "reset" the history on the back button).
_finishToolbarItem.Command = new Command(o => {
Navigation.PopToRootAsync().ContinueWith(task => {
Navigation.PushAsync(new StackOverflow());
},
TaskContinuationOptions.OnlyOnRanToCompletion
);
}
I've tried doing this in an async command wrapper as well:
_finishToolbarItem.Command = new Command(async o => {
await Navigation.PopToRootAsync();
await Navigation.PushAsync(new StackOverflow());
});
Both of these approaches dump me to the root page - but the follow up PushAsync()
is not working, despite it being called in the right order.
How can I "undo" the nav stack in Xamarin Forms (so the "back" buttons don't have anything to go back to) and push a new page?
Upvotes: 3
Views: 3721
Reputation: 146
Try this:
Navigation.InsertPageBefore(new NewPage(),Navigation.NavigationStack[0]);
await Navigation.PopToRootAsync();
Upvotes: 0
Reputation: 5370
You could
InsertPageBefore (Page yourNewRootPage, Page firstPageInNavigationStack)
and then PopToRoot()
Upvotes: 2