How do you specify the Content of a button that is a mix of some TEXT and a Binding path?
Like this:
<Button Content= "TEXT" + "{Binding Path=ButtonContent}"
Binding paths address the different properties and lists in a model and define how a node in the hierarchical data tree can be found. A binding path consists of a number of name tokens, which are separated by a separator char. In all models provided by the framework, the separator char is the slash "/".
Binding path syntax. Use the Path property to specify the source value you want to bind to: In the simplest case, the Path property value is the name of the property of the source object to use for the binding, such as Path=PropertyName . Subproperties of a property can be specified by a similar syntax as in C#.
Two way binding is used when we want to update some controls property when some other related controls property change and when source property change the actual control also updates its property.
The target object is the object that owns the property which we are binding to, i.e. the UI control rendering our data. The target property is the property that has been set via the markup extension, and the source property is the path of the binding.
For most cases you can use StringFormat in the Bindings, like for a TextBlock
<TextBlock Text="{Binding ElementName=textBox, Path=Text, StringFormat='{}{0} - Added Text'}"/>
However, this has no effect on a ContentControl
(which Button
inherits from). Instead, you can use ContentStringFormat
<Button Content="{Binding ElementName=textBox, Path=Text}" ContentStringFormat="{}{0} - Added Text"/>
Also, for
ContentControl
you use ContentStringFormat
HeaderedContentControl
you use HeaderStringFormat
ItemsControl
you use ItemStringFormat
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With