ContentControl.ContentTemplate 屬性
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定用來顯示 ContentControl 內容的資料範本。
public:
property System::Windows::DataTemplate ^ ContentTemplate { System::Windows::DataTemplate ^ get(); void set(System::Windows::DataTemplate ^ value); };
C#
[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
。
- 屬性
下列範例示範如何建立內容範本,並將範本套用至內容控制項。
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 。 如需資料範本的詳細資訊,請參閱 資料範本化概觀。
<object ContentTemplate="{resourceExtension styleResourceKey}"/>
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 |