100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
.NET

TemplateBinding

The lightweight, one-way markup extension used inside a ControlTemplate to connect template visuals to the templated control's own properties.

Markup ExtensionsIntermediate7 min readJul 10, 2026
Analogies

What TemplateBinding Does

{TemplateBinding} is a lightweight, one-way binding used exclusively inside a ControlTemplate to connect a visual element in the template to a property of the control being templated, such as wiring a template's inner Border's Background to the templated Button's own Background property. It exists as a specialized, cheaper alternative to writing {Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background}, which achieves the same conceptual result but with more overhead because it goes through the full data-binding engine rather than the streamlined template binding pathway.

🏏

Cricket analogy: It is like a substitute fielder mirroring the exact hand signals given by the captain without a full radio relay through the coaching staff, a faster and lighter communication path than the general chain of command, just as TemplateBinding is a lighter pathway than a full RelativeSource Binding.

TemplateBinding Limitations vs. RelativeSource TemplatedParent

TemplateBinding only supports one-way, source-to-target data flow and cannot be used with a Converter that needs multi-value input, and it cannot be applied to a property inside a Style Setter's Value in older XAML processors, whereas {Binding RelativeSource={RelativeSource TemplatedParent}} supports the full binding feature set, including TwoWay mode, value converters, and multi-binding. In modern WPF, TemplateBinding is essentially syntactic sugar that the compiler converts into an optimized templated-parent binding, so the practical difference is mostly about brevity and minor performance in the common one-way template scenarios.

🏏

Cricket analogy: It is like a specialist pinch-runner brought on purely to sprint bases, unable to bat or field the way the full-time player they replaced could, just as TemplateBinding trades full binding features for a narrower, faster one-way role.

xml
<Style TargetType="Button">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <Border Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        CornerRadius="4">
                    <ContentPresenter HorizontalAlignment="{TemplateBinding
                                          HorizontalContentAlignment}"
                                      Margin="{TemplateBinding Padding}" />
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

TemplateBinding can only be used directly inside a ControlTemplate applied to elements in that template's visual tree; using it inside a DataTemplate, or trying to feed it through a Style Setter's Value where the templated parent context is not available, will fail or silently produce no value in some XAML processors — use {Binding RelativeSource={RelativeSource TemplatedParent}} in those cases instead.

  • TemplateBinding connects a property inside a ControlTemplate to a property of the control being templated.
  • It is a lighter-weight, one-way-only alternative to {Binding RelativeSource={RelativeSource TemplatedParent}}.
  • TemplateBinding does not support TwoWay mode or multi-value converters.
  • In modern WPF it largely compiles down to an optimized TemplatedParent binding under the hood.
  • It only works inside a ControlTemplate's visual tree, not inside a DataTemplate.
  • Common uses include binding Background, BorderBrush, BorderThickness, and Padding from the control onto template visuals.
  • When TemplateBinding's limitations are hit, falling back to RelativeSource TemplatedParent restores full binding capability.

Practice what you learned

Was this page helpful?

Topics covered

#NET#XAMLStudyNotes#MicrosoftTechnologies#TemplateBinding#Does#Limitations#RelativeSource#TemplatedParent#StudyNotes#SkillVeris