Computer Magic Logo
Special characters

Tuesday, April 12, 2016

Published by Aristotelis Pitaridis

The XAML string properties are enclosed within a pair of double quotes and because XAML is XML, there are some characters that we can not use in the property value. We will see two ways of using special characters in our XAML.

First of all we will see how to use a Unicode character in our XAML. The following example demonstrates how to display the Euro character as part of the text property for a label.

<Label x:Name="MyLabel" Text="Price : 800 &#x20AC;"></Label>

This will have as a result to display the string "Price : 800 €". In order to insert a Unicode character we have to type the characters "&#x", after that we type the hexadecimal value of the Unicode character and finally we type the character ";". If we want to use the decimal value of the Unicode character then we type the characters "&#", after that we type the decimal value of the Unicode character and finally we type the character ";".

The second way of displaying special characters has to do with the characters Angle brackets, ampersands, and quotation marks which have a special meaning in our XAML code. In order to use these characters as part of a value, we can use the standard predefined entities.

Entity Character
&lt; <
&gt; >
&amp; &
&apos; '
&quot; "