【问题标题】:Xamarin Forms - PopToRootAsync and then PushAsync doesn't triggerXamarin Forms - PopToRootAsync 然后 PushAsync 不会触发
【发布时间】:2017-08-01 21:48:16
【问题描述】:

我正在使用 Xamarin Forms,我正在尝试从按钮命令退出导航堆栈 - 并导航到新页面(本质上,我想“重置”后退按钮上的历史记录)。

_finishToolbarItem.Command = new Command(o => {
    Navigation.PopToRootAsync().ContinueWith(task => {
            Navigation.PushAsync(new StackOverflow());
        },
        TaskContinuationOptions.OnlyOnRanToCompletion
    );
}

我也尝试在异步命令包装器中执行此操作:

_finishToolbarItem.Command = new Command(async o => {
    await Navigation.PopToRootAsync();
    await Navigation.PushAsync(new StackOverflow());
});

这两种方法都将我转至根页面 - 但后续 PushAsync() 不起作用,尽管它以正确的顺序调用。

如何“撤消”Xamarin Forms 中的导航堆栈(因此“返回”按钮没有任何可返回的内容)并推送新页面?

【问题讨论】:

    标签: xamarin xamarin.forms


    【解决方案1】:

    你可以

    InsertPageBefore (Page yourNewRootPage, Page firstPageInNavigationStack)
    

    然后PopToRoot()

    【讨论】:

    • 如果你使用 Navigation.PopToRootAsync(),你也可以检查 Navigation.NavigationStack.Count > 0。
    【解决方案2】:

    试试这个:

    Navigation.InsertPageBefore(new NewPage(),Navigation.NavigationStack[0]);
    await Navigation.PopToRootAsync();
    

    【讨论】:

      猜你喜欢
      • 2020-11-24
      • 1970-01-01
      • 2019-11-08
      • 2014-09-19
      • 1970-01-01
      • 1970-01-01
      • 2017-09-15
      • 1970-01-01
      • 2018-03-10
      相关资源
      最近更新 更多