wpf-119135-controls-and-libraries-data-grid-appearance-customization-column-header-customization-header-content-customization.md
This topic describes how to customize the header content. The main part of the header content is a caption. You can change this caption and add different elements to the header content.
Specify the BaseColumn.Header property to change the column header’s caption. The ColumnBase.FieldName property specifies the caption if the BaseColumn.Header property is not specified. Camel-case field names are separated by spaces, for example, the header for the “CategoryName” field name is “Category Name”.
Tip
The code sample below shows how to specify the CategoryName column’s header caption and show it in the center:
<dxg:GridColumn FieldName="CategoryName" Header="Category" HorizontalHeaderContentAlignment="Center"></dxg:GridColumn>
To align content in the column cells, follow the steps below:
<dxg:GridColumn FieldName="CategoryName" Header="Category" HorizontalHeaderContentAlignment="Center">
<dxg:GridColumn.EditSettings>
<dxe:TextEditSettings HorizontalContentAlignment="Center"/>
</dxg:GridColumn.EditSettings>
</dxg:GridColumn>
You can bind a column’s header to a property and specify the StringFormat :
<dxg:GridColumn FieldName="CategoryName" Header="{Binding Path=InterestRate, StringFormat='Interest Rate: ##.0 %'}" />
public class ViewModel {
public double InterestRate { get { return 0.2687; } }
// ...
}
Public Class ViewModel
Public ReadOnly Property InterestRate As Double
Get
Return 0.2687
End Get
End Property
'...
End Class
Specify the BaseColumn.HeaderTemplate property to customize an individual column’s header content. You can specify a common template for all columns in the current GridControl view using the DataViewBase.ColumnHeaderTemplate. The data context (binding source) for these templates is the BaseColumn.HeaderCaption property.
The code sample below shows how to add a button to a header’s content:
<dxg:GridColumn FieldName="CategoryName">
<dxg:GridColumn.HeaderTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding}"></TextBlock>
<Button Content="Button" Margin="0,5,0,0"></Button>
</StackPanel>
</DataTemplate>
</dxg:GridColumn.HeaderTemplate>
</dxg:GridColumn>
View Example: Display an Image within a Column Header
If you have more than one template that defines header content, specify the BaseColumn.HeaderTemplateSelector property to choose a template based on custom logic. Use the BaseColumn.ActualHeaderTemplateSelector property to obtain the actual template selector.
The GridControl displays column headers in the following containers:
The GridControl applies the BaseColumn.HeaderTemplate to column headers in all containers.
For the Column Header Panel, Group Panel, and Column Chooser, you can use the ColumnBase.HeaderPresenterType attached property to determine the header location as demonstrated in the example below:
View Example: Customize Column Headers Based on Their Location
The ColumnBase.FilterEditorHeaderTemplate property allows you to specify a template for headers displayed in the Filter Editor and Filter Panel:
<dxg:GridColumn FieldName="ProductName">
<dxg:GridColumn.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"
FontWeight="Bold"
Foreground="Red"/>
</DataTemplate>
</dxg:GridColumn.HeaderTemplate>
<dxg:GridColumn.FilterEditorHeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"
FontWeight="Bold"
Foreground="Blue"
FontStyle="Italic"/>
</DataTemplate>
</dxg:GridColumn.FilterEditorHeaderTemplate>
</dxg:GridColumn>
Specify the ColumnBase.ColumnHeaderContentStyle property to change the header content’s appearance. Use the DataViewBase.ColumnHeaderContentStyle property to specify the common style applied to all the columns in the current GridControl’s view. The target element for these styles is the ContentControl class.
The code sample below shows how to change the header caption color and increase the font size:
<dxg:GridColumn FieldName="CategoryName">
<dxg:GridColumn.ColumnHeaderContentStyle>
<Style TargetType="{x:Type ContentControl}">
<Setter Property="FontSize" Value="15" />
<Setter Property="Foreground" Value="Red" />
</Style>
</dxg:GridColumn.ColumnHeaderContentStyle>
</dxg:GridColumn>
Tip
Use the ColumnBase.ActualColumnHeaderContentStyle property to obtain the style applied to the column header content.
See Also