我正在开发一个Xamarin应用程序,我想在我的应用程序中使用Xamarin.Forms.Shell进行导航(路由)。您是否知道在Shell中检索已注册路由列表的方法?
例如,考虑下面的SimpleAppShell
public partial class SimpleAppShell : Xamarin.Forms.Shell
{
public SimpleAppShell()
{
InitializeComponent();
RegisterExtraRouting();
BindingContext = this;
}
protected void RegisterExtraRouting()
{
Routing.RegisterRoute("//tab-bar-item/tab-2/page-2", typeof(ContentPage2));
Routing.RegisterRoute("//tab-bar-item/tab-3/page-3", typeof(ContentPage3));
}
public override OnAppearing()
{
base.OnAppearing();
PrintMyRoutes(); // TODO: don't know where to get the info from
}
}和以下与上面的Shell相关的XAML文件
<!--- removed config code for simplicity -->
<TabBar
Route="tab-bar-item">
<Tab
Title="Tab-1"
Route="tab-1"
Icon="tabs_icon.png">
<ShellContent
Route="page-1"
ContentTemplate="{DataTemplate local:ContentPage1}" />
</Tab>
</TabBar>一旦调用了OnAppearing(),我希望在控制台中获得如下内容:
//tab-bar-item/tab-1/page-1
//tab-bar-item/tab-2/page-2
//tab-bar-item/tab-3/page-3在谷歌上找了这个话题后,我还没能找到任何东西。
谢谢您一直鼓励我。
发布于 2020-01-26 10:50:48
method exposing route keys为internal,您需要使用反射来调用此方法。
public SimpleAppShell()
{
InitializeComponent();
RegisterExtraRouting();
BindingContext = this;
MethodInfo getRouteKeysMethodInfo = typeof(Routing).GetMethod("GetRouteKeys", BindingFlags.NonPublic | BindingFlags.Static);
string[] routeKeys = (string[])getRouteKeysMethodInfo.Invoke(null, null);
}https://stackoverflow.com/questions/59914378
复制相似问题