HeaderedContentControl.HeaderTemplate 屬性

定義

取得或設定用來顯示控制項標頭內容的樣板 (Template)。

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

屬性值

DataTemplate

資料範本。 預設為 null

屬性

範例

下列範例會建立兩 DataTemplate 個 物件,以指定 和 Content HeaderedContentControl 的外觀 Header


<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 Attribute Usage

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

XAML 屬性項目用法

XAML 值

ResourceExtension
下列其中一項: StaticResource 、 或 DynamicResource 。 請參閱 XAML 資源

TemplateResourceKey
識別所要求範本的索引鍵。 索引鍵是指 中的 ResourceDictionary 現有資源。

注意

屬性元素語法技術上可行,但不建議使用。 請參閱 內嵌樣式和範本。 您也可以使用 或 來參考系結,但並不常見。

相依性屬性資訊

識別碼欄位 HeaderTemplateProperty
設定為 的中繼資料屬性 true

適用於