【问题标题】:How to remove page from modal stack optimized way(specific)?如何从模式堆栈优化方式中删除页面(具体)?
【发布时间】:2019-04-12 18:10:05
【问题描述】:

我有四页页面 1-page 2-page 3-page 4.我使用推送模式异步进行向前导航。当我点击第 4 页中的按钮单击时,它正在使用下面的代码导航到第 2 页。

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】:

解决方案:

在您的第 4 页中,将以下代码添加到第 2 页的模态弹出窗口:

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,等等...

记得在PopModalAsync 中添加 flase 来避免动画。

【讨论】:

  • @Tester 我的回答解决了你的问题吗?如果是,您可以接受。
猜你喜欢
  • 2019-08-29
  • 2013-10-11
  • 1970-01-01
  • 2016-03-09
  • 1970-01-01
  • 1970-01-01
  • 2013-04-21
  • 1970-01-01
  • 2017-12-18
相关资源
最近更新 更多