2009-12-15 5 views
65

मैं वर्तमान की तरह एक Combobox है निम्नलिखित: इकाई संदर्भ या दृश्यों एक ampersand '&' के साथ शुरुआत:कैसे एंपरसैंड (&) एक ComboBoxItem की सामग्री में शामिल करने के लिए

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

यह एक त्रुटि को जन्म देती है अर्धविराम ';' के साथ समाप्त किया जाना चाहिए।

मुझे लगता है कि मुझे & का उपयोग करने की अनुमति देने के लिए मुझे कुछ प्रकार का भागने का अनुक्रम याद आ रहा है। & को शामिल करने के लिए मैं इस comboboxitem की सामग्री कैसे सेट कर सकता हूं? धन्यवाद

उत्तर

135

एम्परसैंड को एन्कोड करने के लिए &amp; का उपयोग करें।

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

संक्षिप्त उत्तर &amp;एनकोड एक ampersand को उपयोग करने के लिए है।

XML.com पर भी Entities: Handling Special Content देखें:

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

मैं अपने जवाब में शब्दावली (एनकोड बनाम भागने) को सही है। इसे मेरे संज्ञान में लाने के लिए धन्यवाद। –

+0

आपके लिंक में>, <, "और 'के लिए उपयोगी तुलना है।" इकाई संदर्भ \t के साथ शुरू होने वाली तालिका देखें ... " – CrimsonX

+0

एक grt उत्तर है :) thnx :) – Apoorva

7

वैकल्पिक रूप से, आप ComboBoxItem तत्व की सामग्री के आसपास CDATA टैग का उपयोग कर सकते हैं; मुझे लगता है कि यह टेक्स्ट की पठनीयता को बेहतर बनाए रखता है।

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

संदर्भ के लिए: http://www.w3schools.com/xmL/xml_cdata.asp

संबंधित मुद्दे