How to Apply Custom Style for GridHeaderCellControl in WPF DataGrid?
WPF DataGrid 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:
Conclusion
I hope you enjoyed learning how to apply custom style for GridHeaderCellControl in WPF DataGrid.
You can refer to our WPF Grid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WPF Grid example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!