Search code examples
xamlnavigationviewwinui-3

WinUI: How to change NavigationView.Header background color?


I have a NavigationView and would like to change the header background color:

header background with arrow

I have tried:

  • Looking in generic.xaml for likely styles to override
  • Using a HeaderTemplate

Here's my code:

<NavigationView Background="Gray">
    <NavigationView.Header>
        <Border Background="Green">
            <TextBlock Text="Header"/>
        </Border>
    </NavigationView.Header>
    <Border Background="Orange">
        <TextBlock Text="Sweet content"/>
    </Border>
</NavigationView>

Solution

  • Try to override the NavigationViewContentBackground theme resource:

    <NavigationView Background="Gray">
        <NavigationView.Resources>
            <SolidColorBrush x:Key="NavigationViewContentBackground" Color="Red" />
        </NavigationView.Resources>
        <NavigationView.Header>
            <Border Background="Green">
                <TextBlock Text="Header"/>
            </Border>
        </NavigationView.Header>
        <Border Background="Orange">
            <TextBlock Text="Sweet content"/>
        </Border>
    </NavigationView>