[英]Navigation Issue in Xamarin Forms
I need to route pages A -> B -> C -> D, once I got into D, I need to use the navigation button back to page D -> A. I am trying to implement this scenario IOS and Android in Xamarin Forms.我需要路由页面 A -> B -> C -> D,一旦我进入 D,我需要使用导航按钮返回页面 D -> A。我正在尝试在 Xamarin Forms 中实现这个场景 IOS 和 Android .
Please help请帮忙
Your case use the Navigation.PopToRootAsync ();
你的情况使用
Navigation.PopToRootAsync ();
Navigation.PopToRootAsync ();
This method pops all but the RootPage
off the navigation stack, therefore making the root page of the application the active page.此方法从导航堆栈中弹出除
RootPage
之外的所有页面,从而使应用程序的根页面成为活动页面。
Navigation.PopAsync ();
This causes the Page2Xaml
instance to be removed from the navigation stack, with the new topmost page becoming the active page.这会导致
Page2Xaml
实例从导航堆栈中删除,新的最顶层页面成为活动页面。
The following doc explains well about Xamarin.Forms
Navigation.以下文档很好地解释了
Xamarin.Forms
导航。 https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/hierarchical https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/hierarchical
Inside the "D" page override the "OnBackButtonPressed" and inside the function iterate trough the pages you no longer need and remove them one by one.在“D”页面内覆盖“OnBackButtonPressed”,并在函数内部遍历您不再需要的页面并一一删除它们。
Pseudo code:伪代码:
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();
}
You can oveeride OnBackButtonPressed Event and use Navigation.PopToRootAsync您可以监控 OnBackButtonPressed 事件并使用 Navigation.PopToRootAsync
protected override bool OnBackButtonPressed()
{
Navigation.PopToRootAsync();
return base.OnBackButtonPressed();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.