Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange MultiBinding StringFormat issue

Tags:

wpf

xaml

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

like image 612
Friend Avatar asked Jan 25 '12 11:01

Friend


1 Answers

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.

like image 101
Ray Avatar answered Sep 23 '22 03:09

Ray