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)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

public DataTemplate HeaderTemplate { get; set; }
/** @property */
public DataTemplate get_HeaderTemplate ()

/** @property */
public void set_HeaderTemplate (DataTemplate value)

public function get HeaderTemplate () : DataTemplate

public function set HeaderTemplate (value : DataTemplate)

<object HeaderTemplate="{ResourceExtensionTemplateResourceKey}"/>
 ResourceExtension   StaticResource or DynamicResource. StaticResource typically provides better performance.  TemplateResourceKey  An x:Key resource key that refers to a template resource. 

Property Value

A DataTemplate to use to display the column header. The default value is a null reference (Nothing in Visual Basic).

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. For the complete sample, see ListView implementing a GridView with Templates.

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

This example shows how to use the DataTemplate and Style objects to specify the appearance of a ListView control that uses a GridView view mode.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Show: