ContentControl.ContentTemplate 屬性

定義

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

C#
[System.ComponentModel.Bindable(true)]
public System.Windows.DataTemplate ContentTemplate { get; set; }

屬性值

DataTemplate

資料範本。 預設值是 null

屬性

範例

下列範例示範如何建立內容範本,並將範本套用至內容控制項。

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

備註

將這個屬性設定為 , DataTemplate 以指定 的外觀 ContentControl 。 如需資料範本的詳細資訊,請參閱 資料範本化概觀

XAML Attribute Usage

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

XAML 值

resourceExtension
標記延伸,識別如何參考範本資源,或 StaticResource DynamicResource 。 請參閱 XAML 資源

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

備註

屬性元素語法在技術上是可行的,但不建議使用。 如需詳細資訊,請參閱 內嵌樣式和範本

相依性屬性資訊

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

適用於

產品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7