不接受带有“&”的 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
WPF Button content with '&' not accepting
提问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)
- < → < (less-than sign, U+003C)
- > → > (greater-than sign, U+003E)
- " → " (quotation mark, U+0022)
- ' → ' (apostrophe, U+0027)
与具有大量字符实体引用的传统 HTML 不同,在 XML 中只有五个预定义的字符实体引用。这些用于转义在某些上下文中对标记敏感的字符:
- & → &(与号,U+0026)
- < → <(小于号,U+003C)
- > → >(大于号,U+003E)
- " → "(引号,U+0022)
- ’ → '(撇号,U+0027)
回答by Amir Twito
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


