I have been trying to navigate to the specific tab/page on a button event in the page, using the below lines, however, it doesn't work for me.
private void Button_Clicked(object sender, EventArgs e)
{
//Shell.Current.GoToAsync($"//MainPage/Page2", true);
Shell.Current.GoToAsync($"//Page2", true);
}
// My tabs in AppShell.xaml file:
<TabBar x:Name="tb_pages" >
<Tab Title="Page 1" Icon="icon_feed.png" >
<ShellContent ContentTemplate="{DataTemplate local:Page1}" />
</Tab>
<Tab Title="Page 2" Icon="icon_feed.png">
<ShellContent ContentTemplate="{DataTemplate local:Page2}"/>
</Tab>
<TabBar>
//AppShell.cs looks like:
public AppShell()
{
InitializeComponent();
///
Routing.RegisterRoute(nameof(Page1), typeof(Page1));
Routing.RegisterRoute(nameof(Page2), typeof(Page2));
}
I am expecting to navigate to an appropriate tab that is set in my AppShell Navigation line. I just wanna do it programmatically. I am unable to find any tab selection/click event that i could intentionally call and jump to the specific tab i want.
I created a demo and achieved this function, you can refer to the following code.
I added the
Routefor parent elementTabBarand added theRouteinShell.xamlAppShell.xaml.cs
AppShell.xaml
In the first page(
Page1),I added a button and navigate toPage2as follows:Note: if you want to alter to other tab at
AppShell, you can refer to document Tab selection.