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?
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 ();
// 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 ();
Navigation.PopToRootAsync ();
Sends you back to your main page..
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With