How do you style a WPF GridView Header? How do you style a WPF GridView Header? wpf wpf

How do you style a WPF GridView Header?


This is a simple style that will accomplish what you are looking for. Just change the Transparent background on the Border to be your desired gradient.

    <Style TargetType="{x:Type GridViewColumnHeader}">        <Setter Property="Template">            <Setter.Value>                <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">                    <Border BorderThickness="0,0,0,1" BorderBrush="Black" Background="Transparent">                        <TextBlock x:Name="ContentHeader" Text="{TemplateBinding Content}" Padding="5,5,5,0" Width="{TemplateBinding Width}" TextAlignment="Center" />                    </Border>                </ControlTemplate>            </Setter.Value>        </Setter>        <Setter Property="OverridesDefaultStyle" Value="True" />        <Setter Property="Foreground" Value="Black" />        <Setter Property="FontFamily" Value="Segoe UI" />        <Setter Property="FontSize" Value="12" />    </Style>


sometimes the simplest way is the best. All you need to do it to change the TextBlock attached properties of GridViewColumnHeader

Define something like this in Resources:

<Style TargetType="{x:Type GridViewColumnHeader}" BasedOn="{StaticResource {x:Type GridViewColumnHeader}}">    <Setter Property="TextBlock.TextWrapping" Value="Wrap"/>    <Setter Property="TextBlock.Foreground" Value="Black"/></Style>


Have a look at the GridViewColumnHeader.Role property. The sample in the documentation for the GridViewColumnHeaderRole enumeration might give you some ideas...

EDIT: Have you considered using the GridView.HeaderStyle property ?