Vincent
Vincent

Reputation: 3304

Change NavigationView default pane background in cs code

I'm using Microsoft.UI.Xaml.Controls.NavigationView. For some reason, I have to change NavigationView's pane background. So I changed in XAML.

<Page.Resources>
     <SolidColorBrush x:Key="NavigationViewDefaultPaneBackground" Color="{StaticResource ViuPageBackgroundColor1}" />
</Page.Resources>

But now I want to achieve this in cs code, how to do that.

Upvotes: 0

Views: 314

Answers (1)

Roy Li - MSFT
Roy Li - MSFT

Reputation: 8681

The NavigationViewDefaultPaneBackground brush is used for a property called PaneBackground of the Splitview control. The Splitview control called RootSplitView is one of the components of Navigationview.

If you want to change the PaneBackground property in code-behind, you need to search in the NavigationView's template and find the Splitview control by name -RootSplitView. Then when you get the Splitview control, you could change the PaneBackground as you want.

Upvotes: 1

Related Questions