Escaping curly braces in XAML code

Sometimes you want your user interface text contains a curly brace “{“. Unfortunately, the xaml parser will consider it as markup extension and will refuse to compile. For example, the below code will not compile and will give an error: The given key was not present in the dictionary.

TextBlock Text="{Username:"

In order to escape the curly brace, you need to add “{}” before your text brace as shown below:


TextBlock Text="{}{Username:"

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: