Defines the element tree that is applied as the control template for a control.
Inheritance
- Object
- DependencyObject
- FrameworkTemplate
- ControlTemplate
Syntax
<ControlTemplate ...> templateRootElement </ControlTemplate>
XAML Values
- templateRootElement
-
A single object element that derives from FrameworkElement. The templateRootElement is often a panel that contains other elements.
Attributes
- ActivatableAttribute(NTDDI_WIN8)
- MarshalingBehaviorAttribute(Agile)
- ThreadingAttribute(Both)
- VersionAttribute(NTDDI_WIN8)
- WebHostHiddenAttribute()
Members
The ControlTemplate class has these types of members:
Constructors
The ControlTemplate class has these constructors.
| Constructor | Description |
|---|---|
| ControlTemplate | Initializes a new instance of the ControlTemplate class. |
Methods
The ControlTemplate class has these methods. It also inherits methods from the Object class.
| Method | Description |
|---|---|
| ClearValue | Clears the local value of a dependency property. (Inherited from DependencyObject) |
| GetAnimationBaseValue | Returns any base value established for a dependency property, which would apply in cases where an animation is not active. (Inherited from DependencyObject) |
| GetValue | Returns the current effective value of a dependency property from a DependencyObject. (Inherited from DependencyObject) |
| ReadLocalValue | Returns the local value of a dependency property, if a local value is set. (Inherited from DependencyObject) |
| SetValue | Sets the local value of a dependency property on a DependencyObject. (Inherited from DependencyObject) |
Properties
The ControlTemplate class has these properties.
| Property | Access type | Description |
|---|---|---|
| Read-only | Gets the CoreDispatcher that this object is associated with. (Inherited from DependencyObject) | |
| Read/write | Gets or sets the type to which the ControlTemplate is applied. |
Remarks
The content of a template such as ControlTemplate or DataTemplate is not accessible through a simple run-time API. Defining a template is a scenario for XAML language usage, and the value is assigned purely as a XAML parsing operation. There are ways to access template content after it is applied to a specific control; see OnApplyTemplate or GetTemplateChild.
Examples
The following example creates a simple ControlTemplate for a Button. The control template contains one Grid and specifies this behavior:
-
When the user puts the mouse over the Button, the Grid changes from green to red over one half second.
-
When the user moves the mouse away from the button, the Grid immediately changes back to green.
<ControlTemplate TargetType="Button"> <Grid > <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualStateGroup.Transitions> <!--Take one half second to transition to the PointerOver state.--> <VisualTransition To="PointerOver" GeneratedDuration="0:0:0.5"/> </VisualStateGroup.Transitions> <VisualState x:Name="Normal" /> <!--Change the SolidColorBrush, ButtonBrush, to red when the Pointer is over the button.--> <VisualState x:Name="PointerOver"> <Storyboard> <ColorAnimation Storyboard.TargetName="ButtonBrush" Storyboard.TargetProperty="Color" To="Red" /> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Grid.Background> <SolidColorBrush x:Name="ButtonBrush" Color="Green"/> </Grid.Background> </Grid> </ControlTemplate>
Requirements
|
Minimum supported client | Windows 8 [Windows Store apps only] |
|---|---|
|
Minimum supported server | Windows Server 2012 [Windows Store apps only] |
|
Namespace |
|
|
Metadata |
|
See also
Build date: 3/12/2013