Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying a Button Content that has mix of text and a Binding path

Tags:

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}" 
like image 421
user565660 Avatar asked Mar 01 '11 19:03

user565660


People also ask

What is binding path?

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 "/".

Which of the following is the syntax of binding a command to an object in asp net?

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#.

What is two way binding in WPF?

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.

What is target and source in WPF?

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.


1 Answers

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
like image 174
Fredrik Hedblad Avatar answered Oct 07 '22 16:10

Fredrik Hedblad