How to hide the bottom TabbedPage tabs in .NET MAUI 8?

Satya 155 Reputation points
2025-01-28T05:33:26.86+00:00

Actually I need to hide bottom tabs based on some condition.

I tried using TabbedViewHandler and Reflection to hide the tabs by setting height of bototmbar LayoutParameters to 0. Tabs are not visible, but blank space is showing up in space of tabs. I also tried the setting the visibility of bottomBar to Gone, but still white space is showing up. Any help would be highly appreciated.

public static PropertyMapper<BaseBottomBarTabbedPage, CustomTabbedPageHandler> BottomBarMapper = new(Mapper)
 {
     [nameof(BaseBottomBarTabbedPage.IsBottomBarVisible)] = IsBottomBarVisibleOrNot
 };

 private static void IsBottomBarVisibleOrNot(CustomTabbedPageHandler handler, BottomBarTabbedPage baseBottomBarTabbedPage)
 {
     try
     {
         if (handler != null && handler.PlatformView != null && baseBottomBarTabbedPage != null)
         {
             var context = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity.ApplicationContext;
             var flags = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic;
             Type tabbedPageType = typeof(Microsoft.Maui.Controls.TabbedPage);
             var tabManager = tabbedPageType.GetField("_tabbedPageManager", flags)?.GetValue(baseBottomBarTabbedPage);
             var bottomNavigation = tabManager.GetType().GetField("_bottomNavigationView", flags)?.GetValue(tabManager);
             if (bottomNavigation is Google.Android.Material.BottomNavigation.BottomNavigationView bottomBar)
             {
                 var parameters = bottomBar.LayoutParameters;
                 int resourceId = context.Resources.GetIdentifier("design_bottom_navigation_height", "dimen", context.PackageName);
                 if (resourceId > 0)
                 {
                     bottomBarHeight = context.Resources.GetDimensionPixelSize(resourceId);
                 }
                 if (parameters != null)
                 {
                     parameters.Height = baseBottomBarTabbedPage.IsBottomBarVisible ? bottomBarHeight : 0;
                     bottomBar.LayoutParameters = parameters;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Crashes.TrackError(ex);
     }
 }
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,887 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.