Export (0) Print
Expand All

XML Character Entities and XAML

Extensible Application Markup Language (XAML) uses character entities defined in XML for special characters.

Generally speaking, XAML uses the same character entities and escaping that are defined in XML.

The main exception is that curly braces ({ and }) have significance in XAML because these characters inform a XAML processor that a character sequence enclosed within the braces must be interpreted as a markup extension. For more information on markup extensions, see Markup Extensions and XAML.

However, you can still display the curly braces as literal characters by using an escape sequence that is particular to XAML rather than XML. For details, see {} Escape Sequence / Markup Extension.

Note that a backslash (\) does not need to be escaped when handled as a string.

As mentioned previously, most of the character entities and escaping that are commonly used when writing XAML markup are defined by XML. This topic does not provide the complete list of such entities; more definitive reference for the entities can be found in external documentation, such as the XML specifications. However, for convenience, this topic lists some of the specific XML character entities that are commonly used for XAML markup.

Character

Entity

Notes

& (ampersand character)

&

Must be used both for attribute values and for content of an element.

> (greater-than character)

>

Must be used for attribute value, but > is acceptable as the content of an element so long as < does not precede it.

< (less-than character)

&lt;

Must be used for attribute value, but < is acceptable as the content of an element so long as > does not follow it.

" (double quote character)

&quot;

Must be used for attribute value, but " is acceptable as the content of an element. Note that attribute values themselves may be enclosed either by ' or "; whichever character appears first will define the attribute value enclosure, and the alternative quote can then be used as a literal within the value.

' (single quote character)

&apos;

Must be used for attribute value, but ' is acceptable as the content of an element. Note that attribute values themselves may be enclosed either by ' or "; whichever character appears first will define the attribute value enclosure, and the alternative quote can then be used as a literal within the value.

(numeric character mappings)

&#[integer]; or &#x[hex];

XAML supports numeric character mappings into the encoding that is active.

(nonbreaking space)

&#160; (assuming UTF-8 encoding)

For flow document elements, or elements that take text such as TextBox, nonbreaking spaces are not normalized out of the markup, even for xml:space="default" (for details, see Whitespace Processing in XAML).

XAML uses the XML comment format: beginning of comment is <!--, end of comment is -->, and the sequence -- must not occur within the comment.

XAML handles XML processing instructions in accordance to the XML specifications, which state that the instructions must be passed through. The WPF XAML processing does not use any processing instructions.

Community Additions

ADD
Show:
© 2014 Microsoft