Refresh NavigationView item background in WinUI 3

121 Views Asked by At

I am using a NavigationView with a Frame in a user control in WinUI 3 to navigate to a Page. What I want to do is set the background of the selected NavigationViewItem to match the background of the Page that is navigated to.

So far what I am doing is setting the NavigationView's resources using Resources["NavigationViewItemBackgroundSelected"] = the desired color in the Frame.Navigated handler. I also do the same for the "NavigationViewItemBackgroundSelectedPointerOver" resource since the pointer usually is over the item when the item is selected. Setting the resources this way only affects the one NavigationView in the user control, because I redefine these resources within the user control.

When I select a NavigationViewItem, I can see in the code that the resources are being set to the desired color. Unfortunately though, this does not result in the visual appearance of the NavigationViewItem being updated. The update does not happen until an action occurs such as pointer leaving the NavigationViewItem.

How can I force a refresh of the visual appearance of the NavigationView's SelectedItem after setting the "NavigationViewItemBackgroundSelected" and "NavigationViewItemBackgroundSelectedPointerOver" resources?

0

There are 0 best solutions below