NoWar
NoWar

Reputation: 37633

Strange MultiBinding StringFormat issue

I have this XAML

<MultiBinding  StringFormat=" {0}{1}/{2}">
   <Binding Path="Text" ElementName="tbxAuthHost" />
   <Binding Path="Text" ElementName="tbxAuthWebsiteName" />
   <Binding Path="Text" ElementName="tbxAuthServicesAddress" />
</MultiBinding>

When I try change " {0}{1}/{2}" into "{0}{1}/{2}" so no leading space there and then Visual Studio gives this error:

Error 3 The text '{1}/{2}' is not allowed after the closing '}' of a MarkupExtension expression. Line 116 Position 56.

How I can fix this issue?

enter image description here

Upvotes: 9

Views: 2871

Answers (1)

Ray
Ray

Reputation: 46585

You can fix this by putting {} at the front of the string format.

StringFormat="{}{0}{1}/{2}"

The MSDN Page does a particularly bad job of explaining the format.

If you look at the page on the escape sequence it explains that an opening curly bracket at the beginning denotes a markup extension (e.g. Binding), and {0}{1}/{2} is not a valid markup extension. It doesn't explain that not having it as the first character also works.

Upvotes: 17

Related Questions