首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >已注册路由列表

已注册路由列表
EN

Stack Overflow用户
提问于 2020-01-26 07:45:32
回答 1查看 400关注 0票数 3

我正在开发一个Xamarin应用程序,我想在我的应用程序中使用Xamarin.Forms.Shell进行导航(路由)。您是否知道在Shell中检索已注册路由列表的方法?

例如,考虑下面的SimpleAppShell

代码语言:javascript
复制
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文件

代码语言:javascript
复制
<!--- 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(),我希望在控制台中获得如下内容:

代码语言:javascript
复制
//tab-bar-item/tab-1/page-1
//tab-bar-item/tab-2/page-2
//tab-bar-item/tab-3/page-3

在谷歌上找了这个话题后,我还没能找到任何东西。

谢谢您一直鼓励我。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-01-26 10:50:48

method exposing route keysinternal,您需要使用反射来调用此方法。

代码语言:javascript
复制
public SimpleAppShell()
{
    InitializeComponent();
    RegisterExtraRouting();
    BindingContext = this;

    MethodInfo getRouteKeysMethodInfo = typeof(Routing).GetMethod("GetRouteKeys", BindingFlags.NonPublic | BindingFlags.Static);
    string[] routeKeys = (string[])getRouteKeysMethodInfo.Invoke(null, null);
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59914378

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档