Class ControlTemplate
Replaces a Control's entire decorated visual tree (its internal Chrome)
with markup content of the author's own choosing, instead of the control's built-in default.
public class ControlTemplate
- Inheritance
-
ControlTemplate
- Inherited Members
- Extension Methods
Remarks
A ControlTemplate holds a single element's worth of raw markup, captured once when the template itself is loaded (see MarkupLoader's own ControlTemplate special case), and instantiated fresh - via LoadContent(UIElement) - for every control that applies it. Two controls sharing one ControlTemplate each get their own independent visual subtree; nothing built from this template is ever shared or cached across control instances.
Content elements can pull values from the control being templated via {TemplateBinding} (see
TemplateBindingExtension), and a
ContentControl's template typically hosts the control's real
Content through a
ContentPresenter.
Style/VisualState setters are unaffected by templating - they still only ever
target the templated control's own top-level properties (e.g. Background), which a
{TemplateBinding} inside this template's content then reflects.
Constructors
ControlTemplate(Type)
Replaces a Control's entire decorated visual tree (its internal Chrome)
with markup content of the author's own choosing, instead of the control's built-in default.
public ControlTemplate(Type targetType)
Parameters
targetTypeTypeThe type of control this template is meant to be applied to.
Remarks
A ControlTemplate holds a single element's worth of raw markup, captured once when the template itself is loaded (see MarkupLoader's own ControlTemplate special case), and instantiated fresh - via LoadContent(UIElement) - for every control that applies it. Two controls sharing one ControlTemplate each get their own independent visual subtree; nothing built from this template is ever shared or cached across control instances.
Content elements can pull values from the control being templated via {TemplateBinding} (see
TemplateBindingExtension), and a
ContentControl's template typically hosts the control's real
Content through a
ContentPresenter.
Style/VisualState setters are unaffected by templating - they still only ever
target the templated control's own top-level properties (e.g. Background), which a
{TemplateBinding} inside this template's content then reflects.
Properties
TargetType
Gets the type of control this template is meant to be applied to.
public Type TargetType { get; }
Property Value
Methods
LoadContent(UIElement)
Builds a fresh visual tree from this template's content, for templatedControl.
public UIElement LoadContent(UIElement templatedControl)
Parameters
templatedControlUIElementThe control this content is being built for.
Returns
- UIElement
The freshly built root element - never shared with any other call, even for the same control.
Exceptions
- InvalidOperationException
This template was never given any content.
- MarkupException
The content is malformed, or breaks a rule of the markup language.