question

EJ-5254 avatar image
0 Votes"
EJ-5254 asked EJ-5254 commented

MasterDetail page disable hamburger icon in iOS

Hi,

In some cases I need to disable MasterDetail page (or FlyoutPage) hamburger button so users can't open master page. If I set IsGesturesEnabled = false it won't allow users to open master with swipe, but they still can via the button.

Anyway to achieve this? Perhaps using MasterDetail custom renderer and disabling icon there somehow?

Thanks in advance.

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

KyleWang-MSFT avatar image
0 Votes"
KyleWang-MSFT answered EJ-5254 commented

Hi EJ-5254,

Welcome to our Microsoft Q&A platform!

Yes, you can create a custom render for the page you want to disable "menu button".

Here I download the sample Xamarin documentation provides on GitHub: xamarin/xamarin-forms-samples.

To disable the "menu button" on ContactsPage, you can create a custom render for it as follows.

 [assembly: ExportRenderer(typeof(ContactsPage), typeof(CustomPageRenderer))]
 namespace FlyoutPageNavigation.iOS
 {
     class CustomPageRenderer : PageRenderer
     {
         public override void ViewDidLayoutSubviews()
         {
             base.ViewDidLayoutSubviews();
    
             if (NavigationController != null)
             {
                 var items = NavigationController.NavigationBar.Items;
                 if (items.Length != 0)
                 {
                     UIBarButtonItem leftItem = items[0].LeftBarButtonItem;
                     if (NavigationController.ViewControllers.Length == 1)
                     {
                         leftItem.Enabled = false;
                     }
                 }
             }
         }
     }
 }

Regards,
Kyle


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Kyle,

Thank you, this works fine on iPhone, but not on iPad in portrait mode, any ideas why? iPad in landscape mode doesn't even show hamburger icon, so not a problem.

0 Votes 0 ·

@EJ-5254 I tested this on iPad Pro. It's indeed an issue. When the first page selected with the Menu button is "ContactsPage", this method fails. For this, please submit an issue on GitHub: xamarin/xamarin-macios.

0 Votes 0 ·