问题
In my app structure is like below, List Page -> Detail Page -> Edit Page
and in edit page there is button "Delete" which removes data from database.
Now my problem is to navigate user from Edit page to List Page,
I'm using Navigation.popasync 2 times for this, but on detail page i'm getting error from service that no such record exist.
How can i properly navigate user from Edit page to list page?
回答1:
// Remove page before Edit Page
this.Navigation.RemovePage (this.Navigation.NavigationStack [this.Navigation.NavigationStack.Count - 2]);
// This PopAsync will now go to List Page
this.Navigation.PopAsync ();
回答2:
Navigation.PopToRootAsync ();
Sends you back to your main page..
回答3:
That will be because your detail page is trying to load a record that no longer exists on an OnAppearing or some other event. As such just put a condition at the top of if the record is null to not load the page.
回答4:
You can do like this:
var _navigation = Application.Current.MainPage.Navigation;
var _lastPage = _navigation.NavigationStack.LastOrDefault();
//Remove last page
_navigation.RemovePage(_lastPage);
//Go back
_navigation.PopAsync();
But if you need to navigate to the root page you can use this:
var _navigation = Application.Current.MainPage.Navigation;
_navigation.PopToRootAsync ();
来源:https://stackoverflow.com/questions/34084692/remove-page-from-navigation-stack-xamarin-forms