ContentControl.ContentTemplate ContentControl.ContentTemplate ContentControl.ContentTemplate ContentControl.ContentTemplate Property

定义

获取或设置用于显示 ContentControl 内容的数据模板。Gets or sets the data template used to display the content of the 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; }
member this.ContentTemplate : System.Windows.DataTemplate with get, set
Public Property ContentTemplate As DataTemplate

属性值

数据模板。A data template. 默认值为 nullThe default value is null.

示例

下面的示例演示如何创建内容模板并将模板应用到内容控件。The following examples show how to create a content template and apply the template to a content control.

<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 , 以指定的外观。 ContentControlSet this property to a DataTemplate to specify the appearance of the ContentControl. 有关数据模板的详细信息, 请参阅数据模板化概述For more information on data templates, see Data Templating Overview.

XAML 属性用法XAML Attribute Usage

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

XAML 值XAML Values

resourceExtensionresourceExtension
标识如何引用模板资源 ( StaticResourceDynamicResource) 的标记扩展。A markup extension that identifies how to reference the template resource, either StaticResource or DynamicResource. 请参阅XAML 资源See XAML Resources.

styleResourceKeystyleResourceKey
标识所请求模板选择器的键。The key that identifies the requested template selector. 键引用中ResourceDictionary的现有资源。The key refers to an existing resource in a ResourceDictionary.

备注

属性元素语法在技术上是可行的, 但不建议这样做。Property element syntax is technically possible, but not recommended. 有关详细信息, 请参阅内联样式和模板For more information, see Inline Styles and Templates.

依赖项属性信息Dependency Property Information

标识符字段Identifier field ContentTemplateProperty
元数据属性设置为trueMetadata properties set to true NoneNone

适用于