Partager via


Control.Template Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets a control template.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Property Template As ControlTemplate
public ControlTemplate Template { get; set; }
<control Template="{StaticResource templateResourceKey}"/>

XAML Values

  • templateResourceKey
    The key that identifies the template being requested. The key refers to an existing resource in a ResourceDictionary.
NoteNote:

Property element syntax to define an inline template is technically possible, but not recommended for most template scenarios. See Inline Styles and Templates.

Property Value

Type: System.Windows.Controls.ControlTemplate
The template that defines the appearance of the Control.

Remarks

Dependency property identifier field: TemplateProperty

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.

Control templates are typically set in XAML as part of a control-specific implicit style. In this case, a Property value in the style is set as the string Template, and the Setter.Value value is set as a property element, which contains a ControlTemplate object element. For example:

<Style TargetType="ScrollViewer">
...
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="ScrollViewer">
      //visual root of template for a ScrollViewer
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.