如何在Xamarin App Shell中获取当前的Shell内容页面引用?

问题描述 投票:2回答:1

我正在使用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目录页面?

最诚挚的问候。

xamarin xamarin.forms
1个回答
0
投票

花费了很多时间,但我发现了可以满足此需求的公共Shell界面。如果将ShellSection转换为IShellSectionController,则可以使用PresentedPage属性获取当前的Page对象。下面是一个代码段,YMMV。

(Shell.Current?.CurrentItem?.CurrentItem as IShellSectionController)?.PresentedPage
© www.soinside.com 2019 - 2024. All rights reserved.