How to apply custom style for GridHeaderCellControl in WPF ?
SfDataGrid displays the column header in GridHeaderCellControl that displays the column Header Text, filter icon and sort icon when you sort the column. You can apply the custom style for GridHeaderCellControl by using HeaderStyle property.
You can change the header cell Background and Foreground for specific column or an entire Grid by using HeaderStyle property.
Following code example illustrates the custom header style applied for GridHeaderCellControl present in the Grid.
XAML
<Window.Resources> <Style TargetType="syncfusion:GridHeaderCellControl" x:Key="headerStyle"> <Setter Property="Background" Value="#FF7AA732"/> <Setter Property="Foreground" Value="Red"/> </Style> </Window.Resources> <!--Apply style for GridHeaderCellControl present in the grid--> <syncfusion:SfDataGrid x:Name="grid" HeaderStyle="{StaticResource headerStyle}" ItemsSource="{Binding Students}" ColumnSizer="Star" AllowEditing="True">
The following screenshot displays the column header with customized column header style.
Figure 1: Column header with customized column header style
The following code example illustrates the custom header style applied for specific column Header.
XAML
<Window.Resources> <Style TargetType="syncfusion:GridHeaderCellControl" x:Key="headerStyle"> <Setter Property="Background" Value="#FF7AA732"/> <Setter Property="Foreground" Value="Red"/> </Style> </Window.Resources> <syncfusion:SfDataGrid.Columns> <!--Change the HeaderStyle for specific column--> <syncfusion:GridTextColumn MappingName="ProductId" HeaderStyle="{StaticResource headerStyle}"/> </syncfusion:SfDataGrid.Columns>
The following screenshot displays the customized HeaderStyle for specific column.
Figure 2: Customized HeaderStyle for specific column
Sample Links: