Control.Template Control.Template Control.Template Control.Template Property

定义

获取或设置控件模板。Gets or sets a control template.

public:
 property System::Windows::Controls::ControlTemplate ^ Template { System::Windows::Controls::ControlTemplate ^ get(); void set(System::Windows::Controls::ControlTemplate ^ value); };
public System.Windows.Controls.ControlTemplate Template { get; set; }
member this.Template : System.Windows.Controls.ControlTemplate with get, set
Public Property Template As ControlTemplate

属性值

定义 Control 外观的模板。The template that defines the appearance of the Control.

示例

下面的示例Button为创建ControlTemplate一个。The following example creates a ControlTemplate for a Button. 如果将此项作为资源添加到应用程序中, 应用程序中的所有按钮都将显示为省略号, 但仍可用作按钮。If you add this to your application as a resource, all the buttons in the application will appear as ellipses but will still function as buttons.

<Style TargetType="Button">
  <!--Set to true to not get any properties from the themes.-->
  <Setter Property="OverridesDefaultStyle" Value="True"/>
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="Button">
        <Grid>
          <Ellipse Fill="{TemplateBinding Background}"/>
          <ContentPresenter HorizontalAlignment="Center"
                            VerticalAlignment="Center"/>
        </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

注解

Control Control指定的外观; 如果Control没有, 则将不会出现在你的应用程序中。 ControlTemplate ControlTemplateThe ControlTemplate specifies the appearance of a Control; if a Control does not have a ControlTemplate, the Control will not appear in your application. 控件作者定义默认控件模板, 应用程序作者可以重写ControlTemplate来重新定义控件的可视化树。The control author defines the default control template, and the application author can override the ControlTemplate to redefine the visual tree of the control. 有关如何更改现有控件的可视化树的信息和示例, 请参阅控件样式和模板See Control Styles and Templates for information and examples of how to change the visual tree of existing controls.

旨在作为实现详细信息的自包含单元, 该单元对外部用户和对象 (包括Style对象) 不可见。 ControlTemplateA ControlTemplate is intended to be a self-contained unit of implementation detail that is invisible to outside users and objects, including Style objects. 操作控件模板内容的唯一方法是在同一控件模板中。The only way to manipulate the content of the control template is from within the same control template.

依赖项属性信息Dependency Property Information

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

适用于