Issue
I'm developing a Xamarin app and I'd like to use Xamarin.Forms.Shell for navigation (routing) in my app. Do you know, by any chance, which is the way for retrieving the list of registered routes in a Shell?
For instance, consider the following 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
}
}
And the following XAML file related to the Shell
above
<!--- 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>
I would like to get something like following in the console once the OnAppearing() it's called:
//tab-bar-item/tab-1/page-1
//tab-bar-item/tab-2/page-2
//tab-bar-item/tab-3/page-3
After looking for this topic in google, I have not been able to find anything yet.
Thank you for your support.
Solution
The method exposing route keys is internal
, you'll need to use reflection to call this method.
public SimpleAppShell()
{
InitializeComponent();
RegisterExtraRouting();
BindingContext = this;
MethodInfo getRouteKeysMethodInfo = typeof(Routing).GetMethod("GetRouteKeys", BindingFlags.NonPublic | BindingFlags.Static);
string[] routeKeys = (string[])getRouteKeysMethodInfo.Invoke(null, null);
}
Answered By - Roger Leblanc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.