Forum Xamarin Xamarin.Forms

How can I hide or bloCk the master detail page when I'm in one of the pages of the menu?

SpontonLucianoSpontonLuciano Member ✭✭✭
edited December 2019 in Xamarin.Forms

I mean, I got a master Detail which contains Sells, Stock, Buys, Etc.. and when you select "Stock" you go to the stock page, but the menu still appears if you slide the screen from left to right, I don't wanna that happen, I could hide the three menu lines from the navigation page bar but still appears if you slide it, How can I block that action?

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    We could use IsGestureEnabled to turn off the swipe gesture of the Master-Detail Page.
    Firstly, register a messaging center in the constructor of the Master-Detail Page:

    public MainPage()
    {
        InitializeComponent();
    
        MasterBehavior = MasterBehavior.SplitOnPortrait;
        MenuPages.Add((int)MenuItemType.Browse, (NavigationPage)Detail);
    
        MessagingCenter.Subscribe<object, bool>(this, "SwitchMaster", (sender, enabled) =>
        {
            IsGestureEnabled = enabled;
        });
    }
    

    Send the disable signal in the appearing event of your stock page:

    protected override void OnAppearing()
    {
        base.OnAppearing();
    
        MessagingCenter.Send<object, bool>(this, "SwitchMaster", false);
    }
    

    Turn on it at any time as you want:

    protected override void OnDisappearing()
    {
        base.OnDisappearing();
    
        MessagingCenter.Send<object, bool>(this, "SwitchMaster", true);
    }
    
  • LandLuLandLu Member, Xamarin Team Xamurai

    Hi @SpontonLuciano, Did you have any update about this?

  • LuiCLuiC USMember ✭✭

    @LandLu said:
    We could use IsGestureEnabled to turn off the swipe gesture of the Master-Detail Page.
    Firstly, register a messaging center in the constructor of the Master-Detail Page:

    public MainPage()
    {
        InitializeComponent();
    
        MasterBehavior = MasterBehavior.SplitOnPortrait;
        MenuPages.Add((int)MenuItemType.Browse, (NavigationPage)Detail);
    
        MessagingCenter.Subscribe<object, bool>(this, "SwitchMaster", (sender, enabled) =>
        {
            IsGestureEnabled = enabled;
        });
    }
    

    Send the disable signal in the appearing event of your stock page:

    protected override void OnAppearing()
    {
        base.OnAppearing();
    
        MessagingCenter.Send<object, bool>(this, "SwitchMaster", false);
    }
    

    Turn on it at any time as you want:

    protected override void OnDisappearing()
    {
        base.OnDisappearing();
    
        MessagingCenter.Send<object, bool>(this, "SwitchMaster", true);
    }
    

    note: setting IsGestureEnabled to false doesn't hide the menu button on UWP, so this solution, while likely logically correct, may not resolve the issue for cross platform users.

  • SpontonLucianoSpontonLuciano Member ✭✭✭
    edited April 21

    I solve it putting this in my MasterPage constructor

    And this those on my others page that I need to disable

Sign In or Register to comment.