Toggle iOS NavigationPage.SetHasNavigationBar with TabbedPage results in hiding the tabs

DepechieDepechie BEInsider, Developer Group Leader ✭✭

Anyone tried this scenario before? I'm talking about latest Xamarin forms 2 targetting iOS.

I have a TabbedPage with 4 tabs, when the user looks at the first 2, there should not be a navigationbar - I got this working by setting the NavigationPage.SetHasNavigationBar(this, false) in the constructor of the TabbedPage.

Now by using the ExtendedTabbedPage of Xamarin forms labs, I can hook up to the change tab event called OnCurrentPageChanged() and in here I verify if I'm on one of the last 2 tabs and toggle the NavigationPage.SetHasNavigationBar(this, true).

This actually works great, except for 1 small detail. When the navigation bar gets shown, tab page shifts down and it hides the tabs at the bottom, so the user is unable to switch tabs at that moment.

When I set NavigationPage.SetHasNavigationBar(this, true) in the constructor of the tabbedpage and leave it for all tabs, the result is ok. Meaning I get a navigationheader and tabs visible on each tab.

Posts

  • DepechieDepechie BEInsider, Developer Group Leader ✭✭

    Ok found a solution myself.

    So the original setup was as follows, in the App.xaml.cs I initiated the Navigation through following code

    NavigationPage navigationPage = new NavigationPage(new MainPage());

    MainPage is a TabbedPage containing several children.
    What I did was toggling the NavigationBar of that MainPage when switching from one child page to another

    NavigationPage.SetHasNavigationBar(this, false);
    NavigationPage.SetHasNavigationBar(this, true);

    But that resulted in the child pages not being resized, leaving the tabbar at the bottom of the page invisible when the navigationbar came visible.

    So the actual solution is to not set the MainPage as a NavigationPage, but wrap each child in a NavigationPage!
    This way each child can have it's own NavigationBar an that keeps the size in reference to the MainPage correct.
    So adding each child would be like this

    this.Children.Add (new NavigationPage (new DiscoverPage ()){ Title = "Discover" });

    Took me a while to figure this out because I normally would add the children inside the actual xaml of the MainPage but that way you can't wrap them in a NavigationPage, hence why I wrapped the MainPage itself inside the NavigationPage!

Sign In or Register to comment.