Wednesday, September 8, 2010

Working with Special Characters

Every once in awhile you need to work with the following characters in XAML:
  • >
  • <
  • "
  • &
You would get these errors if you put them in a text value:
Error 5 Entity references or sequences beginning with an ampersand ‘&’ must be terminated with a semicolon ‘;’.
Error 4 ‘"’ is an unexpected token. The expected token is ‘;’.

You can encode invalid characters for use in XAML by using the following encoding syntax:


Character


Encoding


<


&lt;


>


&gt;


&


&amp;



&quot;


space


&#160;



&apos;


(numeric character mappings)


&#[integer]; or

&#x[hex];


(nonbreaking space)


&#160; (assuming UTF-8 encoding)