views:

225

answers:

3

I currently have a Combobox like the following:

//XAML
<ComboBox>
<ComboBoxItem> Awake & Alive</ComboBoxItem>
</ComboBox>

This raises an error: Entity references or sequences beginning with an ampersand '&' must be terminated with a semicolon ';'.

I assume I am missing an escape sequence of some sort to allow me to use a &. How can I set the content of this comboboxitem to include a &? Thanks

+4  A: 

Use &amp; to encode the ampersand.

//XAML
<ComboBox>
<ComboBoxItem> Awake &amp; Alive</ComboBoxItem>
</ComboBox>
Andy West
+4  A: 

The short answer is to use &amp; to encode an ampersand.

See also Entities: Handling Special Content on XML.com.

Sinan Ünür
I have corrected the terminology (encode vs. escape) in my answer. Thanks for bringing it to my attention.
Andy West
Your link has useful comparisons for >, <, " and '. See the table starting with "Entity reference Stands for..."
CrimsonX
+3  A: 

Alternatively, you can use the CDATA tag around the contents of the ComboBoxItem element; I think it better maintains the text's readability.

//XAML
<ComboBox>
<ComboBoxItem><![CDATA[Awake & Alive]]></ComboBoxItem>
</ComboBox>

For reference: http://www.w3schools.com/xmL/xml_cdata.asp

chaosTechnician