Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

How can I correctly use a TabbedPage inside a NavigationPage

$
0
0

My app has one NavigationPage with a TabbedPage at its root. I want to hide the navigation bar based on the active tab. Unfortunately, Xamarin doesn't correctly resize my pages once the navigation bar moves in and out of view.

Here's the "bug" in a minimal reproduction:

image

Here's the reproduction's code:

public App()
{
    InitializeComponent();

    // Our tabs
    var bluePage = new ContentPage() { 
        Title = "Blue",
        BackgroundColor = Color.Blue 
    };
    var yellowPage = new ContentPage() { 
        Title = "Yellow",
        BackgroundColor = Color.Yellow 
    };
    var redPage = new ContentPage() { 
        Title = "Red",
        BackgroundColor = Color.Red 
    };


    // Tabbed page to hold tabs
    var tabbedPage = new TabbedPage()
    {
        Title = bluePage.Title,
        Children = {
            bluePage,
            yellowPage,
            redPage
        }
    };

    tabbedPage.CurrentPageChanged += (sender, e) =>
    {
        // Hide the app's navbar for the yellow page
        var shouldHaveNavigation = tabbedPage.CurrentPage != yellowPage;
        NavigationPage.SetHasNavigationBar(tabbedPage, shouldHaveNavigation);

        // Set page title to copy active tab
        tabbedPage.Title = tabbedPage.CurrentPage.Title;
    };


    var navPage = new NavigationPage(tabbedPage);

    MainPage = navPage;

}

I've tried to circumvent the issue by pushing three NavigationPages to the TabbedPage, but I understand this won't work on Android.

Is there a way to prevent the vertical layout glitch I'm currently seeing?


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>