MasterDetail page disable hamburger icon in iOS

EJ 366 Reputation points
2021-09-09T07:23:22.473+00:00

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.

Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. Kyle Wang 5,531 Reputation points Microsoft External Staff
    2021-09-10T02:25:23.477+00:00

    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.


0 additional answers

Sort by: Most helpful

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.