2

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..

rene
  • 41,474
  • 78
  • 114
  • 152
Mirko Bellabarba
  • 562
  • 2
  • 13

2 Answers2

4

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

Damien
  • 2,911
  • 1
  • 25
  • 47
1

I think Messenger will fit well in here, fire it from other Views to update the button.

thang2410199
  • 1,932
  • 2
  • 17
  • 18