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:
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 NavigationPage
s 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?