Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove page from Navigation stack - xamarin.forms

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?

like image 898
Hetal Avatar asked Dec 04 '15 09:12

Hetal


4 Answers

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 ();  
like image 118
Mohamed Ali NOUIRA Avatar answered Nov 07 '22 21:11

Mohamed Ali NOUIRA


// 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 ();
like image 41
Hetal Avatar answered Nov 07 '22 23:11

Hetal


Navigation.PopToRootAsync ();   

Sends you back to your main page..

like image 6
Mr.Koçak Avatar answered Nov 07 '22 23:11

Mr.Koçak


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.

like image 3
Adam Avatar answered Nov 07 '22 21:11

Adam