HeaderedContentControl.HeaderTemplate Свойство

Определение

Возвращает или задает шаблон, используемый для отображения содержимого заголовка элемента управления.

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

Значение свойства

Шаблон данных. Значение по умолчанию — null.

Атрибуты

Примеры

В следующем примере создаются два DataTemplate объекта, чтобы указать внешний вид Header и Content тип 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."/>

Комментарии

Использование атрибута XAML

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

Использование элемента свойства XAML

Значения XAML

ResourceExtension Одно из следующих элементов: StaticResourceили DynamicResource. См. статью "Ресурсы XAML".

TemplateResourceKey Ключ, определяющий запрашиваемый шаблон. Ключ ссылается на существующий ресурс в объекте ResourceDictionary.

Note

Синтаксис элемента свойства технически возможен, но не рекомендуется. См. встроенные стили и шаблоны. Ссылка на привязку, используемая или также возможна, но редко.

Сведения о свойстве зависимостей

Элемент Ценность
Поле идентификатора HeaderTemplateProperty
Свойства метаданных, равные свойству true Нет

Применяется к