[英]Add '&' to WPF TextBox
I have a WPF form, for some reason ONLY '&' character within string cannot be compiled with. 我有WPF表单,出于某种原因,只能使用字符串中的'&'字符进行编译。
<TextBox>=948&showtree=1</TextBox> <!--Error due to char &-->
I have tried: <TextBox Text = @"=948&showtree=1"/>
yet, same result. 我已经尝试过:
<TextBox Text = @"=948&showtree=1"/>
但是,结果相同。
I have tried adding "!@#$%^*()_+"
it also only happens with '&' . 我尝试添加
"!@#$%^*()_+"
它也仅在'&'时发生。 What is so special about '&' and how to overcome this problem within xaml ? “&”有什么特别之处,以及如何在xaml中克服此问题?
I could add it in .cs file but I want to know why did this occurred. 我可以将其添加到.cs文件中,但我想知道为什么会这样。
“&”号是XML中其他代码之前的特殊字符-要使用一个,您需要将用于&号的代码用于&
<TextBox>=948&showtree=1</TextBox>
&
is a special character in XML, which needs to be specified as &
&
是XML中的特殊字符,需要指定为&
, just like <
,就像
<
for <
and >
对于
<
和>
for >
. 为
>
。
So your line should read: 因此,您的行应显示为:
<TextBox>=948&showtree=1</TextBox>
For more information on special characters in XML you can read this: http://xml.silmaril.ie/specials.html 有关XML特殊字符的更多信息,您可以阅读以下内容: http : //xml.silmaril.ie/specials.html
You need to encode the ampersand. 您需要对“&”号进行编码。
Have you tried &
您是否尝试过
&
? ?
See How do I escape ampersands in XML so they are rendered as entities in HTML? 请参阅如何在XML中转成“&”号,以便它们在HTML中呈现为实体?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.