Forum Xamarin.Forms

How to navigate to TabbedPage's child page

henryyuehenryyue Member ✭✭

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

I also asked question on stackoverflow

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

Answers

  • ColeXColeX Member, Xamarin Team Xamurai
    edited May 2019

    MyTabbedPage/ChildTabPage1/Page1

    private void Button_Clicked(object sender, EventArgs e)
        {       
            TabbedPage page = App.Current.MainPage as TabbedPage;
            NavigationPage NavPage = page.Children[1] as NavigationPage;
            page.CurrentPage = NavPage;
            NavPage.PushAsync(new Page2(), false);   //disable the animation
        }
    
  • henryyuehenryyue Member ✭✭

    I should write the issue clearer. I want to do deep linking navigation from MyTabbedPage/ChildTabPage1/Page1 to MyTabbedPage/ChildTabPage2/Page2. The solution you provided work functionally but the page.Children[1] is viewed during the navigation. How to make it work like direct navigation from Page1 to Page2?

  • ColeXColeX Member, Xamarin Team Xamurai

    Is this you want ?

    I think in Page1 , you can use Navigation.PushAsync(new Page2(), true); directly.

  • henryyuehenryyue Member ✭✭

    no, I want to navigate from ChildTabPage1/Page1 to ChildTabPage2/Page2.
    Navigation.PushAsync(new Page2(), true); can't change Tab Page.

  • ColeXColeX Member, Xamarin Team Xamurai
    edited May 2019
        TabbedPage page = App.Current.MainPage as TabbedPage;
        page.CurrentPage = page.Children[1];
    

    The code above change the selected tab ,one more thing is that override the back event of Page2 , check if last page is Page1, if it is , set tab selected index to 0 .

Sign In or Register to comment.