As you know StringFormat is of great importance for data representation in WPF. My problem is how to use StringFormat when multibinding in WPF?
If I give a very simple example:
We have variables,which are A and B and whose values are 10.255555 and 25.6999999
And we want to show them 10.2,25.6
?
How can I do this with multibinding? Normally it is piece of cake with ValueConverter
Any help and ideas on this topic will be greately appreciated
Just set the
StringFormat
property on theMultiBinding
; use placeholders ({0}, {1}...) for each binding in the multibinding, and include format specifiers if necessary (e.g. F1 for a decimal number with 1 decimal digit)The
{}
part at the beginning is the format string is an escape sequence (otherwise the XAML parser would consider{
to be the beginning of a markup extension)To simplify you could use two TextBlock/Labels to display the values.
If you are using .Net4, you can bind in a Run Inline element of a TextBlock
If anyone is looking for "Time Formats" this is for 24hr Clock which is how I came to this post:
The leading 0: and 1: are the reference to the Bindings
[0:hh:mm tt] to display AM/PM