Control.Template 属性

定义

获取或设置控件模板。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

属性值

ControlTemplate

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

示例

下面的示例为创建一个 ControlTemplate ButtonThe 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>

注解

ControlTemplate指定的外观 Control ; 如果没有,则 Control ControlTemplate Control 将不会出现在你的应用程序中。The 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.

ControlTemplate旨在作为实现详细信息的自包含单元,该单元对外部用户和对象(包括对象)不可见 StyleA 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

适用于