不接受带有“&”的 WPF 按钮内容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1220717/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 20:48:09  来源:igfitidea点击:

WPF Button content with '&' not accepting

wpfxamlbutton

提问by Sauron

I am creating and with content 'Save & Add'. I write it in XAML, but the symbol '&' is not accepting. What is the reason for that. How can I do that?

我正在创建内容“保存并添加”。我用 XAML 编写它,但不接受符号“&”。这是什么原因。我怎样才能做到这一点?

回答by Ben Griswold

Use &instead of &.

使用& 代替 &。

You might find this article of some use - How to: Use Special Characters in XAML

您可能会发现这篇文章有些用处 -如何:在 XAML 中使用特殊字符

回答by Cameron MacFarland

From Wikipedia:

来自维基百科

Unlike traditional HTML with its large range of character entity references, in XML there are only five predefined character entity references. These are used to escape characters that are markup sensitive in certain contexts:

  • & → & (ampersand, U+0026)
  • &lt; → < (less-than sign, U+003C)
  • &gt; → > (greater-than sign, U+003E)
  • &quot; → " (quotation mark, U+0022)
  • &apos; → ' (apostrophe, U+0027)

与具有大量字符实体引用的传统 HTML 不同,在 XML 中只有五个预定义的字符实体引用。这些用于转义在某些上下文中对标记敏感的字符:

  • & → &(与号,U+0026)
  • < → <(小于号,U+003C)
  • > → >(大于号,U+003E)
  • " → "(引号,U+0022)
  • ’ → '(撇号,U+0027)

回答by Amir Twito

How to: Use Special Characters in XAML

如何:在 XAML 中使用特殊字符

Markup files that are created in Microsoft Visual Studio are automatically saved in the Unicode UTF-8 file format, which means that most special characters, such as accent marks, are encoded correctly

在 Microsoft Visual Studio 中创建的标记文件会自动以 Unicode UTF-8 文件格式保存,这意味着大多数特殊字符(例如重音符号)都已正确编码

https://msdn.microsoft.com/en-us/library/aa970677(v=vs.100).aspx

https://msdn.microsoft.com/en-us/library/aa970677(v=vs.100).aspx

回答by Peter M

You might need to escape it as "&amp;". See this link.

您可能需要将其转义为“ &amp;”。请参阅此链接