I'm using Template 10 with a hamburger menu for my project. To change the buttons dynamically depending on wether the user is logged in or not, I figured I'd create a ViewModel for the Shell. Unfortunately, it would seem the DataContext is not correctly targeted to the ViewModel.
I've added the data context to the Shell.xaml, but bindings aren't doing their thing. Is there a better way of going about this, or am I doing something wrong.
Shell.xaml snippets:
Setting the data context:
<Page.DataContext>
<viewModels:ShellViewModel x:Name="ViewModel" />
</Page.DataContext>
Binding visibility to viewmodel:
<Controls:HamburgerButtonInfo AutomationProperties.Name="My Journey"
ClearHistory="False"
PageType="views:MyJourneyPage"
Visibility="{Binding LoggedIn, Converter={StaticResource BooleanToVisibilityConverter}}">
ShellViewModel snippet:
private bool _loggedIn;
public bool LoggedIn { get { return _loggedIn; } set { Set(ref _loggedIn, value); } }
Visual Studio is reporting: Error: BindingExpression path error: 'LoggedIn' property not found on 'Template10.Controls.HamburgerButtonInfo'. BindingExpression: Path='LoggedIn' DataItem='Template10.Controls.HamburgerButtonInfo'; target element is 'Template10.Controls.HamburgerButtonInfo' (Name='null'); target property is 'Visibility' (type 'Visibility')
Resolved by changing the visibility binding to:
"{x:Bind Path=ViewModel.LoggedIn, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverterInverse}}"