What's the difference between these 2 bindings:
<ControlTemplateTargetType="{x:type Button}"> <BorderBorderBrush="{TemplateBinding Property=background}"> <ContentPresenter/> </Border></ControlTemplate>
and
<ControlTemplateTargetType="{x:type Button}"> <BorderBorderBrush="{Binding Relativesource={relativesource templatedparent}, Path=background}"> <ContentPresenter/> </Border></ControlTemplate>
TemplateBinding -more limiting than using regular Binding
- More efficient than a Binding but it had less functionality
- Only works inside a ControlTemplate ' s visual tree
- Doesn ' t work with properties on Freezables
- Doesn ' t work within a ControlTemplate ' s Trigger
- Provides a shortcut in setting properties (not as verbose), e.g. {TemplateBinding TargetProperty}
Regular Binding -Does not having above limitations of TemplateBinding
- Respects Parent Properties
- Resets Target values to clear out any explicitly set values
- Example: <ellipse fill= "{Binding relativesource={relativesource templatedparent},path=background}"/>
One more thing-templatebindings don ' t allow value converting. They don ' t allow you to pass a Converter and don't automatically convert int to string for example (which are normal for a Binding).
Templetebinding is a shorthand for binding with templatedparent but it does not expose all the capabilities of the binding Class, for example you can ' t control Binding.mode from Templetebinding.
Reference WPF TemplateBinding vs RelativeSource TemplatedParent
[WPF series-Advanced TemplateBinding vs RelativeSource TemplatedParent]