TemplateBindingExtension TemplateBindingExtension TemplateBindingExtension TemplateBindingExtension Class


Implements a markup extension that supports the binding between the value of a property in a template and the value of some other exposed property on the templated control.

public ref class TemplateBindingExtension : System::Windows::Markup::MarkupExtension
public class TemplateBindingExtension : System.Windows.Markup.MarkupExtension
type TemplateBindingExtension = class
    inherit MarkupExtension
Public Class TemplateBindingExtension
Inherits MarkupExtension


The following example shows a ControlTemplate that defines a ListBox that is horizontal and has rounded corners. The TemplateBinding indicates that the Background of the Border should be synchronized with the Background value that is set on the ListBox. You use TemplateBinding in your ControlTemplate when you want to give the user of your control the control over the values of certain properties. For a discussion of this example, see Styling and Templating.

<Style TargetType="ListBox">
  <Setter Property="Template">
      <ControlTemplate TargetType="ListBox">
        <Border CornerRadius="5" Background="{TemplateBinding ListBox.Background}">
          <ScrollViewer HorizontalScrollBarVisibility="Auto">
            <StackPanel Orientation="Horizontal"

The following example shows the ControlTemplate of the Label control. The HorizontalAlignment and VerticalAlignment properties are bound to the values of the HorizontalContentAlignment and VerticalContentAlignment properties of the Label control that this ControlTemplate is applied to.

<Style x:Key="{x:Type Label}"
  <Setter Property="HorizontalContentAlignment"
          Value="Left" />
  <Setter Property="VerticalContentAlignment"
          Value="Top" />
  <Setter Property="Template">
      <ControlTemplate TargetType="Label">
          <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            RecognizesAccessKey="True" />
          <Trigger Property="IsEnabled"
            <Setter Property="Foreground">
                <SolidColorBrush Color="{DynamicResource DisabledForegroundColor}" />


You use TemplateBinding in template to bind to a value on the control the template is applied to. A TemplateBinding is more efficient than a Binding but it has less functionality. Using a TemplateBinding is equivalent to using a Binding with the RelativeSource property set to RelativeSource.TemplatedParent.

XAML Text Usage

For XAML information, see TemplateBinding Markup Extension.


TemplateBindingExtension() TemplateBindingExtension() TemplateBindingExtension() TemplateBindingExtension()

Initializes a new instance of the TemplateBindingExtension class.

TemplateBindingExtension(DependencyProperty) TemplateBindingExtension(DependencyProperty) TemplateBindingExtension(DependencyProperty) TemplateBindingExtension(DependencyProperty)

Initializes a new instance of the TemplateBindingExtension class with the specified dependency property that is the source of the binding.


Converter Converter Converter Converter

Gets or sets the converter that interprets between source and target of a binding.

ConverterParameter ConverterParameter ConverterParameter ConverterParameter

Gets or sets the parameter to pass to the converter.

Property Property Property Property

Gets or sets the property being bound to.


Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ProvideValue(IServiceProvider) ProvideValue(IServiceProvider) ProvideValue(IServiceProvider) ProvideValue(IServiceProvider)

Returns an object that should be set as the value on the target object's property for this markup extension. For TemplateBindingExtension, this is an expression (TemplateBindingExpression) that supports the binding.

ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to