ContentControl.ContentTemplate 屬性

定義

取得或設定用於顯示內容 ContentControl的資料範本。

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

屬性值

一個資料範本。 預設值為 null

屬性

範例

以下範例說明如何建立內容範本並將範本套用到內容控制項。

<DataTemplate x:Key="template1">
  <TextBlock Text="{Binding}" FontSize="12" FontWeight="Bold" TextWrapping="Wrap"></TextBlock>
</DataTemplate>
<ContentControl Name="contCtrl" ContentTemplate="{StaticResource template1}" 
    Content="This is the content of the content control."/>

備註

將此屬性設為 以 DataTemplate 指定 的外觀 ContentControl。 欲了解更多資料範本資訊,請參閱 資料模板概述

XAML 屬性使用方式

<object ContentTemplate="{resourceExtension styleResourceKey}"/>

XAML 值

resourceExtension 一個標記擴充,用來識別如何參考範本資源,無論是 StaticResourceDynamicResource。 請參閱 XAML 資源

styleResourceKey 識別所請求範本選擇器的鍵。 該金鑰指 ResourceDictionary的是 .

Note

屬性元素語法技術上是可行的,但不建議使用。 欲了解更多資訊,請參閱 內嵌樣式與範本

相依財產資訊

項目 價值
識別碼欄位 ContentTemplateProperty
元資料屬性設為 true 沒有

適用於