如何从模态堆栈优化方式(特定)中删除页面?

问题描述 投票:1回答:1

我有四页第1页第2页第3页第4页。我使用push modal async来向前导航。当我点击按钮时,单击第4页使用下面的代码,它将导航到page2。

foreach (var page in Navigation.ModalStack)
{
    if (page is Page3)
    {
        await PopModalPage();
    }
}

foreach (var page in Navigation.ModalStack)
{
    if (page is Page4)
    {
        await PopModalPage();
    }
}

要从第4页导航到第2页我正在使用此代码任何优化的方式?请指导。

c# xamarin.forms
1个回答
0
投票

解:

在您的第4页中,将以下代码添加到模式pop到page2:

private  void Button_Clicked(object sender, EventArgs e)
{
    gobackAsync();
}

public async void gobackAsync() {

    int totalModals = Application.Current.MainPage.Navigation.ModalStack.Count;

    //i set currModal = 1 here to back to page 2, If you wan to go back to 3, you can set currModal = 2, etc...
    // remember to add flase in PopModalAsync to aviod the animation.

    for (int currModal = 1; currModal < totalModals; currModal++)
    {
        await Application.Current.MainPage.Navigation.PopModalAsync(false);
    }
}

我在那里设置currModal = 1回到第2页,如果你想回到3,你可以设置currModal = 2等...

请记住在qazxsw poi中添加flash以避免动画。

© www.soinside.com 2019 - 2024. All rights reserved.