【问题标题】:Xamarin.Forms Prism Remove View from Navigation stackXamarin.Forms Prism 从导航堆栈中删除视图
【发布时间】:2017-07-26 15:00:49
【问题描述】:

是否可以从导航堆栈中删除视图?

这就是我想要实现的目标:

  • 导航至查看 1
  • 导航至查看 2
  • 导航到视图 3

如果我在视图 3 中按下“返回”按钮,我想转到视图 1。

【问题讨论】:

    标签: xamarin xamarin.forms prism


    【解决方案1】:

    这应该可以工作

    _navigationService.NavigateAsync("yourApp:///NavigationPage/YourPage")
    

    这相当于

    MainPage = new NavigationPage(new YourPage());
    

    注意:我在iOS以这种方式导航时遇到了崩溃问题。我通过Device.RuntimePlatform解决了它

    switch (Device.RuntimePlatform)
    {
        case Device.iOS:
            _navigationService.NavigateAsync("YourPage");
            break;
        case Device.Android:
            _navigationService.NavigateAsync("yourApp:///NavigationPage/YourPage");
            break;
        default:
            _navigationService.NavigateAsync("YourPage");
            break;
    }
    

    【讨论】:

      【解决方案2】:
      Navigation.RemovePage(Navigation.NavigationStack.Last());
      Navigation.PopAsync();
      

      【讨论】:

      • Prism 的 INavigationService 不公开这些方法
      • 这些是 ContentView 方法
      • 不幸的是,我需要在我的 ViewModel 中调用它,使用 Prism 的 NavigationService
      猜你喜欢
      • 2017-03-09
      • 2016-03-09
      • 2012-05-04
      • 1970-01-01
      • 1970-01-01
      • 2017-07-27
      • 2021-04-24
      • 1970-01-01
      • 2020-12-07
      相关资源
      最近更新 更多