[PRISM] How show/hide programmatically the masterdetailpage (menu) ?

voidstreamvoidstream FRMember ✭✭✭
edited April 2017 in Xamarin.Forms

Hello,

How i can show/hide the master with Prism?

Best regards

Best Answers

  • voidstreamvoidstream FR ✭✭✭
    Accepted Answer

    @KayKuo said:

    @voidstream said:
    public partial class Master : MasterDetailPage
    {
    public Master(IEventAggregator eventAggregator)
    {
    InitializeComponent();
    eventAggregator.GetEvent<Events.ShowHideMenuEvent>().Subscribe(ChangeIsPresented);
    }

    private void ChangeIsPresented()
    {
    IsPresented = !IsPresented;
    }

    private void BindablePicker_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    IsPresented = false;
    }
    }

    Works fine :)

    Can you provide specific code? I also need, thank you.

    I can't provide more like this.

    The MasterDetailPage has "IsPresented" property, which you can show/hide the menu. Now, how to access to this property from another viewmodel? Easy! Use eventAggregator!

    Create a simple eventAggregator which get a bool in parameter

    internal class DisplayMenuEvent : PubSubEvent<bool> { }
    

    Subscribe to this event on the master detail page.
    And in your others viewmodels (pages), publish it

Answers

  • voidstreamvoidstream FRMember ✭✭✭

    Thanks, that was easier for me because i just hide the menu after a selectIndexChanged in the menu ;)

  • voidstreamvoidstream FRMember ✭✭✭
        public partial class Master : MasterDetailPage
        {
            public Master(IEventAggregator eventAggregator)
            {
                InitializeComponent();
                eventAggregator.GetEvent<Events.ShowHideMenuEvent>().Subscribe(ChangeIsPresented);
            }
    
            private void ChangeIsPresented()
            {
                IsPresented = !IsPresented;
            }
    
            private void BindablePicker_SelectedIndexChanged(object sender, System.EventArgs e)
            {
                IsPresented = false;
            }
        }
    

    Works fine :)

  • voidstreamvoidstream FRMember ✭✭✭
    Accepted Answer

    @KayKuo said:

    @voidstream said:
    public partial class Master : MasterDetailPage
    {
    public Master(IEventAggregator eventAggregator)
    {
    InitializeComponent();
    eventAggregator.GetEvent<Events.ShowHideMenuEvent>().Subscribe(ChangeIsPresented);
    }

    private void ChangeIsPresented()
    {
    IsPresented = !IsPresented;
    }

    private void BindablePicker_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    IsPresented = false;
    }
    }

    Works fine :)

    Can you provide specific code? I also need, thank you.

    I can't provide more like this.

    The MasterDetailPage has "IsPresented" property, which you can show/hide the menu. Now, how to access to this property from another viewmodel? Easy! Use eventAggregator!

    Create a simple eventAggregator which get a bool in parameter

    internal class DisplayMenuEvent : PubSubEvent<bool> { }
    

    Subscribe to this event on the master detail page.
    And in your others viewmodels (pages), publish it

Sign In or Register to comment.