Skip to main content

BaseColumn.HeaderTemplate Property

Gets or sets the template that defines the column header’s presentation. This is a dependency property.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v23.2.Core.dll

NuGet Package: DevExpress.Wpf.Grid.Core

Declaration

public DataTemplate HeaderTemplate { get; set; }

Property Value

Type Description
DataTemplate

A DataTemplate object that defines the column header’s presentation.

Remarks

Specify the HeaderTemplate property to customize header content for an individual column. You can use the DataViewBase.ColumnHeaderTemplate property to specify a common template applied to all columns in the GridControl. The data context (binding source) for these templates is the BaseColumn.HeaderCaption property.

The following code sample demonstrates how to change header content:

ColumnHeaderCustomizationHeaderTemplate

<dxg:GridColumn FieldName="CategoryName">
   <dxg:GridColumn.HeaderTemplate>
      <DataTemplate>
         <StackPanel>
            <TextBlock Text="{Binding}"/>
            <Button Content="Button" Margin="0,5,0,0"/>
         </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.

Customize Header Content Based on Location

The GridControl displays column headers in the following containers:

The GridControl applies the 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:

FilterEditorHeaderTemplate

<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>

Refer to the following help topic for more information: Header Content Customization.

See Also