Avoiding issues when typing text in Bindings

.NET, Silverlight, Technical stuff, Work, WPF
See comments

The Binding class has a few properties that can be set to a text, including spaces. The properties StringFormat, TargetNullValue and FallbackValue are such properties. These properties exist in WPF and newly also in Silverlight 4.

For example, you can type:

Since these strings are typed within the Binding markup extension in XAML, they do not take quote signs, which leads the XAML editor to be a little confused, as the color coding shows: The text after the “This” turns to red in the figure above.

Color alone is not really an issue, but another factor makes these strings very difficult to enter by default: The editor is configured to enter a comma after each Property/Value pair in the Binding expression. If you open the XAML editor and start typing such a binding expression, you will end up with:

Of course this will crash and burn. However you can correct this: In Visual Studio 2010, select the menu Options / Text Editor / XAML / Miscellaneous and uncheck the option “Commas to separate MarkupExtension parameters”.

From now on, commas will not be added automatically, and you will feel free!

Previous entry | Next blog entry

Comments for Avoiding issues when typing text in Bindings