Modifica

Condividi tramite


Control.Template Property

Definition

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

Property Value

The template that defines the appearance of the Control.

Examples

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>

Remarks

The ControlTemplate specifies the appearance of a Control; if a Control does not have a ControlTemplate, the Control will not appear in your application. 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.

A 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
Metadata properties set to true AffectsMeasure

Applies to