This documentation is archived and is not being maintained.

TemplateBindingExtension Class

Updated: February 2009

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.

Namespace:  System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)

public class TemplateBindingExtension : MarkupExtension
For XAML information, see TemplateBinding Markup Extension.

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.

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}" TargetType="Label">
  <Setter Property="HorizontalContentAlignment" Value="Left"/>
  <Setter Property="VerticalContentAlignment" Value="Top"/>
  <Setter Property="Template">
      <ControlTemplate TargetType="Label">
            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
          <Trigger Property="IsEnabled" Value="false">
            <Setter Property="Foreground"
                    Value="{StaticResource DisabledForegroundBrush}"/>


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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




February 2009

Corrected information about TemplateBindingExtension being equivalent to the RelativeSource property.

Content bug fix.