-
Notifications
You must be signed in to change notification settings - Fork 406
Description
Describe the bug
I have a user control page that contains a navigationview with navigationviewitems that I use as buttons. I bind those items to my view model (it implements INotifyPropertyChanged and all the properties throw PropertyChanged events). I bind the IsEnabled and Visibility properties of the navigationviewitems to the view model. These bindings are ignored when loading the page. But later if I run a method that changes those settings, they update as desired.
Steps to reproduce the bug
Create a user control containing a NavigationView.
Add MenuItems like this:
<NavigationViewItem.ContentTemplate>
</NavigationViewItem.ContentTemplate>
<!-- Find Focus Align -->
<NavigationViewItem x:Name="FocusAlignButton" Content="Find Focus Align" Tag="FocusAlign"
Tapped="FocusButton_Tapped"
Visibility="{x:Bind VertexVM.IsFocusAlignVisible, Converter={StaticResource BooleanToVisibilityConverter}}"
FontSize="{StaticResource OatFontSizeBody}">
<NavigationViewItem.ContentTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Spacing="10">
<Image Source="ms-appx:///SharedResources_UI3/NewIcons/FindFocus_Icon.svg" Width="30" Height="30"/>
<TextBlock Text="{Binding ElementName=VertexAssemblyPage, Path=HardwareVM.FocusScanButtonText, Mode=OneWay}" VerticalAlignment="Center" FontSize="{StaticResource OatFontSizeBody}"/>
</StackPanel>
</DataTemplate>
</NavigationViewItem.ContentTemplate>
</NavigationViewItem>
(note that neither binding method works)
Make a viewmodel with the properties:
#region IsFocusVisible
private bool isFocusVisible;
public bool IsFocusVisible
{
get { return isFocusVisible; }
set { isFocusVisible = value; OnPropertyChanged(); }
}
#endregion
#region IsFocusAlignVisible
private bool isFocusAlignVisible;
public bool IsFocusAlignVisible
{
get { return isFocusAlignVisible; }
set { isFocusAlignVisible = value; OnPropertyChanged(); }
}
#endregion
Expected behavior
If I set isFocusVisible = false, the NavigationViewItem will not appear. Otherwise it does. All of this works when I later execute methods that change the state and set the properties.
Screenshots
No response
NuGet package version
Windows App SDK 1.8.3: 1.8.251106002
Packaging type
Unpackaged
Windows version
Windows 11 version 24H2 LTSC (26100, June Update)
IDE
Visual Studio 2022
Additional context
... and I've used both ChatGPT and M365 Copilot to try many methods for setting up the code. I've tried setting properties after Loaded, on NavigateTo, within the CTOR, with and without the DispatcherQueue.