How to use stringformat in multibinding in WPF XAML

Jeet Verma

Total Post:110


Posted by  Jeet Verma
 6259  View(s)
Rate this:

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

  1. Re: How to use stringformat in multibinding in WPF XAML

    Hi Jeet,

    Just set the StringFormat property on the MultiBinding; 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)

            <MultiBinding StringFormat="{}{0:F1}{1:F1}">
                <Binding Path="A" />
                <Binding Path="B" />

    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)

      Modified On Mar-31-2018 01:47:07 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.