wpf 如何在包含双引号和单引号的 XAML 中显示文本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1103337/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to display a text in XAML which contains double and single quotation marks?
提问by Edward Tanguay
In my XAML file I want to display this text which contains doubleandsinglequotation marks:
在我的 XAML 文件中,我想显示包含双引号和单引号的文本:
You shouldn't choose "Copy if New".
您不应该选择“如果新建则复制”。
None of these work:
这些都不起作用:
<TextBlock Text="You shouldn't choose "Copy if New":"/>
<TextBlock Text="You shouldn't choose ""Copy if New"":"/>
<TextBlock Text="You shouldn't choose \"Copy if New\":"/>
<TextBlock Text='You shouldn't choose \"Copy if New\":'/>
<TextBlock Text='You shouldn\'t choose \"Copy if New\":'/>
I give up, can I do this in XAML?
我放弃了,我可以在 XAML 中做到这一点吗?
回答by Julien Poulin
You should encode the special characters:
您应该对特殊字符进行编码:
<TextBlock Text='You shouldn't choose "Copy if New":'/>
'
for'
"
for"
'
为了'
"
为了"
回答by Steve Gilham
There are defined XML escapes &
"
for " and &
'
for ' -- if the XML handling in XAML
doesn't interpret those properly, then start to worry.
&
"
为 " 和&
'
'定义了 XML 转义——如果 XML 处理XAML
没有正确解释这些,那么开始担心。
回答by Iván Gimeno
If you don't want to encode special chars you could use:
如果您不想编码特殊字符,您可以使用:
<TextBlock>
<TextBlock.Text>
You shouldn't choose "Copy if New":
<TextBlock.Text>
</TexBlock>