如何在XAML中显示包含双引号和单引号的文本?

时间:2022-02-18 06:56:27

In my XAML file I want to display this text which contains double and single quotation 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做这个吗?

2 个解决方案

#1


73  

You should encode the special characters:

您应该对特殊字符进行编码:

<TextBlock Text='You shouldn&apos;t choose &quot;Copy if New&quot;:'/>

#2


8  

There are defined XML escapes &amp; &quot; for " and &amp; &apos; for ' -- if the XML handling in XAML doesn't interpret those properly, then start to worry.

有已定义的XML转义和放大器;“;“和,'for——如果XAML中的XML处理不能正确地解释它们,那么就开始担心了。

#1


73  

You should encode the special characters:

您应该对特殊字符进行编码:

<TextBlock Text='You shouldn&apos;t choose &quot;Copy if New&quot;:'/>

#2


8  

There are defined XML escapes &amp; &quot; for " and &amp; &apos; for ' -- if the XML handling in XAML doesn't interpret those properly, then start to worry.

有已定义的XML转义和放大器;“;“和,'for——如果XAML中的XML处理不能正确地解释它们,那么就开始担心了。