Hello,
Welcome to our Microsoft Q&A platform!
The index
of the previousPage in the NavigationStack
is not FirstOrDefault()
, stack follows the LIFO
(Last In First Out) principle. So, its index is NavigationStack.Count - 2
. You could also use the name of page to find which page you want to remove, refer to the following code:
private void Button_Clicked(object sender, EventArgs e)
{
//var previousPage = Navigation.NavigationStack.OfType<FirstPage>()?.FirstOrDefault();
//Navigation.RemovePage(previousPage);
//this.Navigation.PopAsync();
this.Navigation.RemovePage(this.Navigation.NavigationStack[this.Navigation.NavigationStack.Count - 2]);
this.Navigation.PopAsync();
}
In fact, FirstPage
has been removed, however, we need pop the current page to check the effect.
Best Regards,
Wenyan Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.