我現在有這樣一個組合框以下:如何包括在ComboBoxItem的內容和號(&)
//XAML
<ComboBox>
<ComboBoxItem> Awake & Alive</ComboBoxItem>
</ComboBox>
這就提出了一個錯誤: 實體引用或序列與符號「&」開頭必須以分號';'結尾。
我假設我錯過了某種轉義序列以允許我使用&。我如何設置此組合框的內容以包含&? 謝謝
我現在有這樣一個組合框以下:如何包括在ComboBoxItem的內容和號(&)
//XAML
<ComboBox>
<ComboBoxItem> Awake & Alive</ComboBoxItem>
</ComboBox>
這就提出了一個錯誤: 實體引用或序列與符號「&」開頭必須以分號';'結尾。
我假設我錯過了某種轉義序列以允許我使用&。我如何設置此組合框的內容以包含&? 謝謝
使用&
來編碼和號。
//XAML
<ComboBox>
<ComboBoxItem> Awake & Alive</ComboBoxItem>
</ComboBox>
簡短的回答是使用&
到編碼的符號。
也Entities: Handling Special Content查看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 & George</company>
.
或者,您可以使用周圍的ComboBoxItem元素的內容的CDATA標籤;我認爲它更好地保持了文本的可讀性。
//XAML
<ComboBox>
<ComboBoxItem><![CDATA[Awake & Alive]]></ComboBoxItem>
</ComboBox>
我已經糾正了我的答案的術語(編碼與逃逸)。感謝您的關注。 – 2009-12-15 16:55:20
你的鏈接對於>,<,「和'有用的比較。參見表格以」實體參考\t代表...「 – CrimsonX 2009-12-15 16:55:56
這是一個grt答案:) thnx :) – Apoorva 2012-10-16 06:27:09