Bearbeiten

Freigeben über


HeaderedItemsControl.HeaderTemplate Property

Definition

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

public:
 property System::Windows::DataTemplate ^ HeaderTemplate { System::Windows::DataTemplate ^ get(); void set(System::Windows::DataTemplate ^ value); };
[System.ComponentModel.Bindable(true)]
public System.Windows.DataTemplate HeaderTemplate { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.HeaderTemplate : System.Windows.DataTemplate with get, set
Public Property HeaderTemplate As DataTemplate

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.

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

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

Identifier field HeaderTemplateProperty
Metadata properties set to true None

Applies to

See also