TemplateBinding markup extension (Windows Store apps using C#/VB/C++ and XAML)

0 out of 3 rated this helpful - Rate this topic

Links the value of a property in a control template to the value of some other exposed property on the templated control. TemplateBinding can only be used within a ControlTemplate definition in XAML.

XAML attribute usage

<object propertyName="{TemplateBinding targetProperty}" .../>

XAML attribute usage (for Setter property in template or style)

<Setter Property="propertyName" Value="{TemplateBinding targetProperty}" .../>

XAML values

TermDescription

propertyName

The name of the property being set in the setter syntax. This must be a dependency property.

targetProperty

The name of a dependency property that exists on the type being templated.

 

Remarks

Using TemplateBinding is a fundamental part of how you define a control template, either if you are a custom control author or if you are replacing a control template for existing controls. For more info, see Quickstart: Control templates.

It's fairly common for propertyName and targetProperty to use the same property name. In this case, a control might define a property on itself and forward the property to an existing and intuitively named property of one of its component parts. For example, a control that incorporates a TextBlock in its compositing, which is used to display the control's own Text property, might include this XAML as a part in the control template: <TextBlock Text="{TemplateBinding Text}" .... />

Attempting to use a TemplateBinding outside of a ControlTemplate definition in XAML will result in a parser error.

TemplateBinding is a markup extension. Markup extensions are typically implemented when there is a requirement to escape attribute values to be other than literal values or handler names, and the requirement is more global than just putting type converters on certain types or properties. All markup extensions in XAML use the "{" and "}" characters in their attribute syntax, which is the convention by which a XAML processor recognizes that a markup extension must process the attribute.

Note  In the Windows Runtime XAML processor implementation, there is no backing class representation for TemplateBinding. TemplateBinding is exclusively for use in XAML markup. There isn't a straightforward way to reproduce the behavior in code.

Related topics

Quickstart: Control templates
ControlTemplate
XAML overview

 

 

Build date: 11/28/2012

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.