2009-12-15 5 views
65

aufzunehmen habe ich zur Zeit eine Combobox wie folgt aus:Wie ein kaufmännische Und (&) in dem Inhalt eines ComboBoxItem

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

Dieses einem Fehler auslöst: Entity-Referenzen oder Sequenzen mit einem Et-Zeichen beginnen ‚&‘ muss mit einem Semikolon ';' abgeschlossen werden.

Ich nehme an, ich vermisse eine Escape-Sequenz irgendeiner Art, um mir zu erlauben, eine & zu verwenden. Wie kann ich den Inhalt dieses Comboboxitems auf & setzen? Danke

Antwort

135

Verwenden Sie &amp;, um das kaufmännische Und zu kodieren.

//XAML 
<ComboBox> 
<ComboBoxItem> Awake &amp; Alive</ComboBoxItem> 
</ComboBox> 
16

Die kurze Antwort ist &amp;-kodieren ein kaufmännische zu verwenden.

Siehe auch Entities: Handling Special Content auf 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> .

+0

ich die Terminologie korrigiert haben (codieren vs. Flucht) in meiner Antwort. Danke, dass du mich darauf aufmerksam gemacht hast. –

+0

Ihr Link enthält nützliche Vergleiche für>, <, "und". Siehe Tabelle beginnend mit "Entitätsreferenz \t steht für ..." – CrimsonX

+0

Das ist eine GRT Antwort :) thnx :) – Apoorva

7

Alternativ können Sie die CDATA-Tag rund um den Inhalt des ComboBoxItem Element verwenden können; Ich denke, es hält die Lesbarkeit des Textes besser aufrecht.

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

Zum Vergleich: http://www.w3schools.com/xmL/xml_cdata.asp

Verwandte Themen