Remove page from Navigation stack - xamarin.forms

半腔热情 提交于 2021-02-07 02:03:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!