Posted by The Reddest on 10/27/2008

2 comments
Skill

Escaping Curly Braces in XAML

Posted in:

You may have already come across this dilemma - needing to put curly braces in the content of a XAML object - like a TextBlock. In XAML, { and } are used to denote markup extensions, so they can't be used without escaping them. Unfortunately, the escape mechanism is far from obvious.

In order to put curly braces in XAML, you must precede the literal with an empty set of braces - {}.

<!-- This works fine -->
<TextBlock Text="{}This is {my} text!" />

<!-- This will result in a compile error -->
<TextBlock Text="This is {my} text!" />

MSDN has posted an article explaining this escape sequence in detail, so check there for more information.

Sanket Vasa
10/28/2008 - 06:26

Not the most intuitive way to escape special characters...
Btw, shouldn't it be "precede" instead of "proceed" :)

reply

The Fattest
10/28/2008 - 07:16

Sanket, thanks for the comment the grammar mishap has been fixed. :)

reply

Add Comment

Put code snippets inside language tags:
[language] [/language]

Examples:
[javascript] [/javascript]
[actionscript] [/actionscript]
[csharp] [/csharp]

See here for supported languages.

Javascript must be enabled to submit anonymous comments - or you can login.