繁体   English   中英

Xamarin 表单中的导航问题

[英]Navigation Issue in Xamarin Forms

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

请帮忙

你的情况使用Navigation.PopToRootAsync ();

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

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

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

在“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();

    }

您可以监控 OnBackButtonPressed 事件并使用 Navigation.PopToRootAsync

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

    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM