Search code examples
uwpuwp-xamlwindows-community-toolkit

UWP Community Tookit dynamic HamburgerMenuGlyphItem labels


I have implemented a Hamburger Menu using the community toolkit which started out nicely. I am now trying to add the ability to change the items in the menu. For example I want one of the OptionItems to display logged in status. If not logged in I want it to say Log In, if they are I want it to show their name. I tried adding a standard x:Bind to the label but it does not work:

<controls:HamburgerMenuGlyphItem Label="{x:Bind Path=UserProfileViewModel.UserName}" Tag="SignIn" Glyph="Contact" />

Using this exact same binding on a TextBlock outside the Hamburger menu works fine, the user name is displayed once they have logged in.

Anyone have any idea how to implement binding within the MenuItems?


Solution

  • So the solution provided by mm8 indeed work. However, in getting that to work I discovered how to solve the initial problem without having to go to any extra effort. Adding the Mode=TwoWay (OneWay works also) to the TextBlock binding in the DataTemplate solved the issue of getting the label to update when the property changes. I then found that the databinding on the HamburgerMenuGlyphItem itself also needs this 'Mode' value setting. Once I added the Mode to that binding as well the label started updating when a user signs in and does not need any external code at all :)