Export (0) Print
Expand All

HeaderedItemsControl.HeaderTemplate Property

Gets or sets the template used to display the contents of the control's 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

[BindableAttribute(true)]
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 data template used to display a control's header. The default is null.

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

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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.

Show:
© 2014 Microsoft