aytee77 aytee77 - 1 year ago 103
C# Question

OnAppearing check from which Page the User is comming in Xamarin.forms

Is there a way i can detect, from which page the user is coming inside of the OnAppearing event in a ContentPage? As well as by pushing a Page to the Navigation or poping it.

I'm trying to do something like this.

protected override void OnAppearing()
if(/*User comes from certain page*/){
//Do stuff
//Do other stuff

Answer Source

Using the NavigationStack you can view the Pages that have been pushed into the stack.

content.Appearing +=  (sender, e) =>
    var pages = Application.Current.MainPage.Navigation.NavigationStack;
    foreach (var page in pages)

Thus, you just have to look at the second to last page to determine where you are coming from....

Something like: