Search code examples
c#.netwpfxamlwpfdatagrid

How to change column header's background color when using WPF datagrid


How to change column header's background color when using WPF datagrid? Need to modify xaml directly?


Solution

  • Use a style with a setter targeted at DataGridColumnHeader:

    <DataGrid>
        <DataGrid.Resources>
            <Style BasedOn="{StaticResource {x:Type DataGridColumnHeader}}" TargetType="{x:Type DataGridColumnHeader}">
                <Setter Property="Background" Value="Blue" />
            </Style>
        </DataGrid.Resources>
    </DataGrid>