我正在使用App Shell开发Xamarin Forms应用程序。
[我发现我必须处理AppContent.xaml.cs中的Android硬件后退按钮,而不是ShellContent页面。
protected override bool OnBackButtonPressed()
{
//Get currernt shell content and call its method
//like (Shell.Current.Content as MyContentPage).MyMethod();
}
1)如何在AppShell.xaml.cs中获得当前的Shell内容页面引用?
2)如何在不进行路由的情况下以编程方式更改当前Shell目录页面?
最诚挚的问候。
花费了很多时间,但我发现了可以满足此需求的公共Shell界面。如果将ShellSection
转换为IShellSectionController
,则可以使用PresentedPage
属性获取当前的Page
对象。下面是一个代码段,YMMV。
(Shell.Current?.CurrentItem?.CurrentItem as IShellSectionController)?.PresentedPage