【问题标题】:Navigation Issue in Xamarin FormsXamarin 表单中的导航问题
【发布时间】:2020-05-26 13:22:50
【问题描述】:

我需要路由页面A -> B -> C -> D,一旦我进入D,我需要使用导航按钮回到页面D -> A。我正在尝试实现这个场景IOS和Android在 Xamarin 表单中。

请帮忙

【问题讨论】:

标签: xaml xamarin xamarin.forms xamarin.android xamarin.ios


【解决方案1】:

您的案例使用Navigation.PopToRootAsync ();

Navigation.PopToRootAsync (); 此方法将除RootPage 之外的所有内容从导航堆栈中弹出,从而使应用程序的根页面成为活动页面。

Navigation.PopAsync (); 这会导致 Page2Xaml 实例从导航堆栈中删除,新的最顶层页面成为活动页面。

以下文档很好地解释了Xamarin.Forms Navigation。 https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/hierarchical

【讨论】:

    【解决方案2】:

    在“D”页面内部覆盖“OnBackButtonPressed”并在函数内部遍历您不再需要的页面并将它们一一删除。

    伪代码:

        protected override bool OnBackButtonPressed()
        {
            foreach (var page in Navigation.NavigationStack)
            {
    
                //find the pages you want to remove
                Navigation.RemovePage(PageYouFound);
            }
            //Set new page
            return base.OnBackButtonPressed();
    
        }
    

    【讨论】:

      【解决方案3】:

      您可以覆盖 OnBackButtonPressed 事件并使用 Navigation.PopToRootAsync

      protected override bool OnBackButtonPressed()
          {
              Navigation.PopToRootAsync();
              return base.OnBackButtonPressed();
      
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-11-26
        • 1970-01-01
        • 2021-02-24
        • 2018-11-30
        • 2017-01-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多