Say I have defined a button with rounded corners.
<Style x:Key="RoundButton" TargetType="Button">
<!-- bla bla -->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border CornerRadius="0,5,5,0" />
<!-- bla bla -->
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I it possible that the user of this button can specify the CornerRadius? Can I use a TemplateBinding? But where should I bind to? (to Tag?)
In order to use a
TemplateBinding, there must be a property on the templated control (Button, in this case).Buttondoes not have aCornerRadiusor equivalent property, so your options are:Tag) to store this information. This is quicker, but lacks type safety, is harder to maintain, and prevents other uses of that property.Buttonand add the propery you need, then provide a template for that subclass. This takes a little longer but yields a much nicer experience for consumers of your control.