Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

GridViewColumn.HeaderTemplate Property

Gets or sets the template to use to display the content of the column header.

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
public DataTemplate HeaderTemplate { get; set; }
<object HeaderTemplate="{ResourceExtension TemplateResourceKey}"/>

XAML Values

ResourceExtension

One of the following: StaticResource, or DynamicResource. See XAML Resources.

TemplateResourceKey

The key that identifies the template being requested. The key refers to an existing resource in a ResourceDictionary.

NoteNote

Property element syntax is technically possible, but not recommended. See Inline Styles and Templates. A binding reference using TemplateBinding or Binding is also possible, but uncommon.

Property Value

Type: System.Windows.DataTemplate
A DataTemplate to use to display the column header. The default is null.

Identifier field

HeaderTemplateProperty

Metadata properties set to true

None

If both the HeaderTemplateSelector property and the HeaderTemplate property are set, the HeaderTemplate property takes precedence.

After a HeaderTemplate or ColumnHeaderTemplate is specified for a GridViewColumn, it cannot be changed.

You can also define the display of a column header by specifying a ControlTemplate as part of a GridViewColumn.HeaderContainerStyle.

Properties that define the content, layout, and style of a column header are found on many related classes, and some of these properties have functionality that is similar or the same. For more information, see GridView Column Header Styles and Templates Overview.

The following example shows how to specify a template to use to display the header of a GridViewColumn.

<DataTemplate x:Key="myHeaderTemplate">
  <DockPanel>
    <CheckBox/>
    <TextBlock FontSize="16" Foreground="DarkBlue">
      <TextBlock.Text>
        <Binding/>
      </TextBlock.Text>
    </TextBlock>
  </DockPanel>
</DataTemplate>
<GridViewColumn Header="Month" Width="80"
      HeaderContainerStyle="{StaticResource myHeaderStyle}"
      HeaderTemplate="{StaticResource myHeaderTemplate}"
      DisplayMemberBinding="{Binding Path=Month}"/>

More Code

How to: Use Templates to Style a ListView That Uses GridViewThis example shows how to use the DataTemplate and Style objects to specify the appearance of a ListView control that uses a GridView view mode.

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.