xamarin - 注册路线一览

标签 xamarin xamarin.forms xamarin.forms.shell

我正在开发 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
    }

}

和下面的 XAML 文件与上面的 Shell 相关

<!--- 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

在 google 中查找此主题后,我还没有找到任何内容。

感谢您的支持。

最佳答案

method exposing route keys内部的,你需要使用反射来调用这个方法。

public SimpleAppShell()
{
    InitializeComponent();
    RegisterExtraRouting();
    BindingContext = this;

    MethodInfo getRouteKeysMethodInfo = typeof(Routing).GetMethod("GetRouteKeys", BindingFlags.NonPublic | BindingFlags.Static);
    string[] routeKeys = (string[])getRouteKeysMethodInfo.Invoke(null, null);
}

关于xamarin - 注册路线一览,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59914378/

相关文章:

c# - XAML 中的 Xamarin.Forms ListView 自动高度

xaml - 全局路由当前不能是堆栈中的唯一页面

xaml - 如何更改 Shell 弹出菜单的宽度/高度

xamarin - 如何在 Xamarin 中以编程方式更改导航栏的背景颜色?

Xamarin.Forms "java.exe"在 Debug模式下以代码 1 退出

Xamarin 表单选项卡式分页滑动调用事件

c# - Xamarin Forms WebView 代理

c# - 自定义所选(当前)FlyoutItem 的样式

c# - 无法在 SlidingUpPanelLayout Xamarin Android 中使用 ScrollView 布局

android - Xamarin Android "ScrollView"奇怪的行为