Search code examples
c#mvvmwinrt-xamlwin-universal-apptemplate10

Modify HamburgerButtonVisibility property from different views


I'm using the fantastic Template10 for my Universal App and MVVM..
What I'm trying to do is to hide and show the hamburger button declared in the Shell.xaml file from a different view. The ideal solution would be something like.. If I don't say nothing, then show the hamburger button, otherwise, hide the hamburger button..
Let's suppose I have the MainPage and when I click an item in the list I navigate to the DetailsPage, in the constructor I send a message or set a property that infor the ShellView to hide the Hamburger button. What's the best practice for doing that?
Messenger can be a possibilty imho but I'm not sure that is the best solution..


Solution

  • If you are using Template10 then in the Shell.xaml.cs you should have this:

      public static Shell Instance { get; set; }
    
            public static HamburgerMenu HamburgerMenu { get { return Instance.MyHamburgerMenu; } }
    
            public Shell()
            {
                Instance = this;
                this.InitializeComponent();
            }    
    

    Which will allow you to access the shell instance from anywhere from you app, and with code:

    var h = Shell.HamburgerMenu;
      h.HamburgerButtonVisibility = MyVisibilityParam;
    

    you can acces the visibility of the HamburgerButton, MyVisibilityparam here can be Visibility.Collapsed or Visibility.Visible