Tip: Curly brackets in XAML Binding's ConverterParameter

WinUI XAML WPF

7 years ago

While working on an UWP app, I wanted to create a string.Format based value converter, so that I could provide a format string in the ConverterParameter , augment the data bound value with it and use the result as a key for a localized string from resources. When I tried to build the project however, I was met with the following cryptic error message:

Child node "2" exited prematurely. Shutting down. 
Diagnostic information may be found in files in the
temporary files directory named MSBuild_*.failure.txt.

Although the nor the error nor the generated diagnostic were too helpful, because I have mostly added just the new XAML binding, I suspected the error must be hidden there.

{Binding 
   Converter={StaticResource TypeNameLocalizingConverter}, 
   ConverterParameter={0}_Description}

As you might expect, it is not possible to use curly brackets directly inside the XAML binding expression. Solution is simple - escaping with backslash.

{Binding 
   Converter={StaticResource TypeNameLocalizingConverter}, 
   ConverterParameter=\{0\}_Description}

With this little change, the code will compile and the value converter works as expected.