Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
Control Class
 Template Property
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
Control..::.Template Property

Updated: November 2007

Gets or sets a control template. This is a dependency property.

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/xaml/presentation

Visual Basic (Declaration)
Public Property Template As ControlTemplate
Visual Basic (Usage)
Dim instance As Control
Dim value As ControlTemplate

value = instance.Template

instance.Template = value
C#
public ControlTemplate Template { get; set; }
Visual C++
public:
property ControlTemplate^ Template {
    ControlTemplate^ get ();
    void set (ControlTemplate^ value);
}
J#
/** @property */
public ControlTemplate get_Template()
/** @property */
public  void set_Template(ControlTemplate value)
JScript
public function get Template () : ControlTemplate
public function set Template (value : ControlTemplate)
XAML Property Element Usage
<object>
  <object.Template>
    <ControlTemplate .../>
  </object.Template>
</object>

Property Value

Type: System.Windows.Controls..::.ControlTemplate

The template that defines the appearance of the Control.

Identifier field

TemplateProperty

Metadata properties set to true

AffectsMeasure

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 ControlTemplate Examples 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.

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.

C#
<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>

Windows Vista

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker