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

前端 未结 5 996
一生所求
一生所求 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:54

    I was trying to do the same thing - what I've wound up doing is a bit of a hack, but does work and keep the back button of page 2 going to page 1.

    Basically,

    var page3 = _navi.NavigationStack.FirstOrDefault(p => p is Page3Type);
    if(page3 != null)
    {
        _navi.RemovePage(page3);
    }
    await navi.PopAsync();
    

    What this does is first, if present, remove page3. Now that that's gone, it pops, and you're back at page 2.

提交回复
热议问题