How to PopAsync more than 1 page in Xamarin Forms Navigation?

前端 未结 5 995
一生所求
一生所求 2021-02-07 04:27

In my app I\'m pushing pages using a NavigationPage and at some stage I want to go back to a previous page in the stack. This is my structure:

NavigationPag

5条回答
  •  误落风尘
    2021-02-07 04:46

    This worked exceptionally well for me:

    I set up a counter and threw a DisplayAlert to find out how many pages I needed to remove

    var x = Navigation.NavigationStack.Count();
    DisplayAlert("Page Count", x.ToString(), "OK");
    

    And then used that to remove the number I needed to fall back.

    Navigation.RemovePage(Navigation.NavigationStack[Navigation.NavigationStack.Count - 2]);
    await Navigation.PopAsync();
    

提交回复
热议问题