HeaderedItemsControl.HeaderTemplate Property

Definition

Gets or sets the template used to display the contents of the control's header.

C#
[System.ComponentModel.Bindable(true)]
public System.Windows.DataTemplate HeaderTemplate { get; set; }

Property Value

A data template used to display a control's header. The default is null.

Attributes

Examples

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

XAML
<!--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>
XAML
<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>
XAML
<!--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}" />

Remarks

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

XAML Attribute Usage

<object HeaderTemplate="{ResourceExtension TemplateResourceKey}"/>

XAML Property Element Usage

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.

Note

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

Dependency Property Information

Item Value
Identifier field HeaderTemplateProperty
Metadata properties set to true None

Applies to

Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

See also