travelinglion
travelinglion

Reputation: 61

Xamarin.Forms: How to navigate to TabbedPage's child page

I meet a scenario to navigate from MyTabbedPage/ChildTabPage1/Page1 to MyTabbedPage/ChildTabPage2/Page2 in Xamarin.Forms

Right now, I can only switch between MyTabbedPage/ChildTabPage1 and MyTabbedPage/ChildTabPage2. But I need to navigate directly from MyTabbedPage/ChildTabPage1/Page1 to MyTabbedPage/ChildTabPage2/Page2

How to achieve this? Thank you very much in advance for your helps.

Upvotes: 0

Views: 1185

Answers (2)

Cherry Bu - MSFT
Cherry Bu - MSFT

Reputation: 10346

If you want to navigate MyTabbedPage/ChildTabPage1/Page1 to MyTabbedPage/ChildTabPage2/Page2 in Xamarin.Forms, I suggest you can consider to use Shell to do this.

Xamarin.Forms Shell includes a URI-based navigation experience that uses routes to navigate to any page in the application, without having to follow a set navigation hierarchy. In addition, it also provides the ability to navigate backwards without having to visit all of the pages on the navigation stack.

Here is the article about using Shell:https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/navigation

Upvotes: 0

Pragnesh Mistry
Pragnesh Mistry

Reputation: 416

You can try something like this.

public App()
{
  InitializeComponent();
  var parentPage = new MasterDetailView(); // name of the master detail page
  parentPage.IsPresented = false;
  var tabbedPage = new MasterDetailTabbedPage(); // name of the tabbed page
  tabbedPage.CurrentPage = tabbedPage.Children[2]; // specify the index of the tab 
  parentPage.Detail = new NavigationPage(tabbedPage); // assign the tabbed page to master detail page
  MainPage = parentPage; // navigate to master detail page (3rd tab selected)
 }

Upvotes: 1

Related Questions