Template bindings
Posted by: Mark Shurmer
If you want to, for example, to override a control template for a control in WPF, it is quite easy and very powerful.
One great thing is that you can specify a templatebinding instead of a (slightly) convoluted syntax to specify the property you are binding to. An example:
<TextBox Text=“{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ValueString}“
This points the text property, in your template, to gets it’s value from the property called ValueString in the xaml that specifies the textbox instance, however it can be changed to:
<TextBox Text=“{TemplateBinding Path=ValueString}“
Much simpler isn’t it.
It also has the benefit of being more efficient than the first version as well, it justs gets better doesn’t it.
However, there is a downside, as I found to my cost yesterday
It is one-way only, so if you keep wondering why changes are not being propagated back, wonder no more.
If you want two-way, then you need the first version unfortunately



You must be logged-in to post a comment. Log-in/Register