HeaderTemplate Property
Collapse the table of content
Expand the table of content

HeaderedContentControl.HeaderTemplate Property

 

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

Namespace:   System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)

[BindableAttribute(true)]
public DataTemplate HeaderTemplate { get; set; }

Property Value

Type: System.Windows.DataTemplate

A data template. The default is null.

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

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.

System_CAPS_noteNote

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

Identifier field

HeaderTemplateProperty

Metadata properties set to true

None

The following example creates two DataTemplate objects to specify the appearance of the Header and Content of the HeaderedContentControl.


<Style TargetType="HeaderedContentControl">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type HeaderedContentControl}">
        <StackPanel>
          <Grid>
            <Rectangle Stroke="{TemplateBinding Background}"/>
            <ContentPresenter ContentSource="Header"/>
          </Grid>
          <Grid>
            <Rectangle Fill="{TemplateBinding Background}"/>
            <ContentPresenter ContentSource="Content"/>
          </Grid>
        </StackPanel>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

<DataTemplate x:Key="titleText">
  <TextBlock Text="{Binding}" 
             Foreground="Green" 
             FontSize="16" 
             FontWeight="Normal"
             FontStyle="Italic" 
             TextWrapping="Wrap"/>
</DataTemplate>

<DataTemplate x:Key="contentText">
  <TextBlock Text="{Binding}"
             Foreground="Brown"
             FontSize="12"
             FontWeight="Normal"
             FontFamily="Arial Narrow" 
             TextWrapping="Wrap"/>
</DataTemplate>
<HeaderedContentControl Name="hcontCtrl" Background="Beige" 
                        HeaderTemplate="{StaticResource titleText}" 
                        ContentTemplate="{StaticResource contentText}"
                        Header="This is the header."
                        Content="This is the content."/>

.NET Framework
Available since 3.0
Return to top
Show:
© 2016 Microsoft