Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include an ampersand (&) in the content of a ComboBoxItem

Tags:

escaping

xaml

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 &?

like image 737
CrimsonX Avatar asked Dec 15 '09 16:12

CrimsonX


People also ask

How do you insert an ampersand?

Typing Ampersand in WindowsHold alt key and type 0038 from the number pad on your keyboard to produce &. Alternatively, on Word documents you can type the hexadecimal code 0026 using normal number keys and then press alt and x keys. This will convert the code into & symbol for you.

How do you use the & symbol?

& is called an ampersand symbol (pronounced “AM- per-sand”). Essentially, it means “and”. It is used both (a) in the body of the paper as part of a citation and (b) at the end of the paper as part of a reference.

Do you put a space between &?

Don't Use Spaces around Ampersands in Abbreviation or Initials. Don't put spaces between ampersands and the surrounding letters in abbreviations or initials used in place of spelled-out names.

How do you use ampersand in titles?

The ampersand should always be used when it's part of a company name, logo, proper noun, or title. This is one of the few cases where ampersand use isn't up for debate. For example, “M&M's” would never be written “M and M's.”


2 Answers

Use &amp; to encode the ampersand.

//XAML <ComboBox> <ComboBoxItem> Awake &amp; Alive</ComboBoxItem> </ComboBox> 
like image 136
Andy West Avatar answered Oct 09 '22 07:10

Andy West


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

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

At the lowest levels an XML parser is just a program that reads through an XML document a character at a time and analyzes it in one way or another, then behaves accordingly. It knows that it's got to process some content differently than other content. What distinguishes these special cases is the presence of such characters as "&" and "<". They act as flags to the parser; they delimit the document's actual content, alerting the parser to the fact that it must do something at this point other than simply pass the adjacent content to some downstream application.

... So one way to get around your immediate problem is to replace the ampersand in your content with the appropriate entity reference: <company>Harris &amp; George</company>.

like image 35
Sinan Ünür Avatar answered Oct 09 '22 09:10

Sinan Ünür