I am using the following method to set the pagenumber of my current page:
protected override void OnAppearing()
{
base.OnAppearing();
// Page number
_pageNumber = Navigation.NavigationStack.Count - 2;
}
Everything works fine, if I am navigating forward and pushing a new page onto the stack like this:
private async void btnContinue_Clicked(object sender, EventArgs e)
{
// Proceed to next view
await Navigation.PushAsync(new MainPage());
}
However, when I am navigating back from one page, the OnAppearing() method seems to be called before the previous page is popped. Thus, the _pageNumber variable will effectively be the one of the previous page. How do I work around that? I thought of placing it inside the constructor but the NavigationStack.Count always returns 0 in there.
My pages are dynamically programmed, therefore, I cannot hardcode the page number into the page because the same page is called but the values are changing based on the number of the page.
