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

  • Question

  • User265422 posted

    Hello,

    How i can show/hide the master with Prism?

    Best regards

    Tuesday, April 18, 2017 12:04 AM

Answers

  • User116727 posted

    This is not something built into Prism. You will have to create a custom implementation. For example, data binding to the IsPresented property to a property in your ViewModel.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, April 18, 2017 4:02 AM
  • User76049 posted

    I ended up using event aggregator as I had edge cases where you could do Rg.Plugin.Popup navigation with a level of transparency and I wanted to close the slide drawer from various different viewmodels.

    Also used behaviors in the master page to close the page.

    ```

    public void DismissPopout(object sender, EventArgs e)
        {
            IsPresented = false;
        }
    

    ```

    Not sure if that's strictly mvvm friendly but it works well :)

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, April 18, 2017 8:49 AM
  • User377481 posted

    @voidstream said: public partial class Master : MasterDetailPage { public Master(IEventAggregator eventAggregator) { InitializeComponent(); eventAggregator.GetEvent().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.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, November 7, 2018 6:59 AM
  • User265422 posted

    @KayKuo said:

    @voidstream said: public partial class Master : MasterDetailPage { public Master(IEventAggregator eventAggregator) { InitializeComponent(); eventAggregator.GetEvent().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

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, November 7, 2018 1:53 PM
  • User377481 posted

    @voidstream thank you

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, November 8, 2018 1:11 AM

All replies

  • User116727 posted

    This is not something built into Prism. You will have to create a custom implementation. For example, data binding to the IsPresented property to a property in your ViewModel.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, April 18, 2017 4:02 AM
  • User76049 posted

    I ended up using event aggregator as I had edge cases where you could do Rg.Plugin.Popup navigation with a level of transparency and I wanted to close the slide drawer from various different viewmodels.

    Also used behaviors in the master page to close the page.

    ```

    public void DismissPopout(object sender, EventArgs e)
        {
            IsPresented = false;
        }
    

    ```

    Not sure if that's strictly mvvm friendly but it works well :)

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, April 18, 2017 8:49 AM
  • User265422 posted

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

    Tuesday, April 18, 2017 6:25 PM
  • User265422 posted
        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 :)

    Monday, May 1, 2017 12:51 PM
  • User377481 posted

    @voidstream said: public partial class Master : MasterDetailPage { public Master(IEventAggregator eventAggregator) { InitializeComponent(); eventAggregator.GetEvent().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.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, November 7, 2018 6:59 AM
  • User265422 posted

    @KayKuo said:

    @voidstream said: public partial class Master : MasterDetailPage { public Master(IEventAggregator eventAggregator) { InitializeComponent(); eventAggregator.GetEvent().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

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, November 7, 2018 1:53 PM
  • User377481 posted

    @voidstream thank you

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, November 8, 2018 1:11 AM