This documentation is archived and is not being maintained.

HeaderedItemsControl.HeaderTemplate Property

Gets or sets the template used to display the contents of the control's header. This is a dependency property.

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

[BindableAttribute(true)] 
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>
  <object.HeaderTemplate>
    <DataTemplate .../>
  </object.HeaderTemplate>
</object>
<object HeaderTemplate="{resourceExtension templateKey}"/>
 resourceExtension  A markup extension that identifies how to reference the template resource, either StaticResource or DynamicResource. See Resources Overview.  templateKey  The key that identifies the requested template. The key refers to an existing resource in a ResourceDictionary. 

Property Value

A data template used to display a control's header. The default is a null reference (Nothing in Visual Basic).

Identifier field

HeaderTemplateProperty

Metadata properties set to true

None

To customize the heading of the HeaderedItemsControl, set this property to a DataTemplate. For more information on data templates, see Data Templating Overview.

The following example shows how to create and use a header template to specify the appearance of the header.

  <!--Define a control template for a HeaderedItemsControl-->
  <Style TargetType="HeaderedItemsControl">
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type HeaderedItemsControl}">
          <StackPanel>
            <Grid>
              <Rectangle Fill="{TemplateBinding Background}"/>
              <ContentPresenter ContentSource="Header"/>
            </Grid>
            <Grid>
              <Rectangle Stroke="{TemplateBinding BorderBrush}"/>
              <ItemsPresenter Margin="2,0,0,0"/>
            </Grid>
          </StackPanel>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

...

  <DataTemplate x:Key="RedHeaderTemplate">
    <TextBlock Text="{Binding}" Foreground="Red" 
               FontSize="16" FontWeight="Bold" 
               TextWrapping="Wrap"/>
  </DataTemplate>

  <DataTemplate x:Key="GreenItemTemplate">
    <TextBlock Text="{Binding}" Foreground="Green" 
               FontSize="14" FontWeight="Bold"></TextBlock>
  </DataTemplate>

...

  <!--Crate a HeaderedItemControl with a red header and green items.-->
  <HeaderedItemsControl Name="hitemsCtrl"  
                        Background="DarkBlue" 
                        BorderBrush="Black"
                        Header="Header"
                        HeaderTemplate="{StaticResource RedHeaderTemplate}"
                        ItemsSource="{Binding Source={StaticResource Numbers}}"
                        ItemTemplate = "{StaticResource GreenItemTemplate}" />

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: