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

更新:2007 年 11 月

在 Microsoft Visual Studio 中创建的标记文件自动以 Unicode UTF-8 的文件格式保存,这意味着大多数特殊字符(如重音符号)都会正确编码。不过,有一组常用特殊字符的处理方式有所不同。这些特殊字符遵循万维网联合会 (W3C)XML 编码标准。

下表显示了对这组特殊字符进行编码所用的语法:

字符

语法

说明

<

&lt;

小于号。

>

&gt;

大于号。

&

&amp;

“and”符。

"

&quot;

双引号。

说明:

如果使用文本编辑器(如 Windows 记事本)创建标记文件,则必须以 Unicode UTF-8 文件格式保存文件以保留任何编码的特殊字符。

下面的示例演示在创建标记时如何在文本中使用特殊字符。

示例

<!-- Display special characters that require special encoding: < > & " -->
<TextBlock>
  &lt;    <!-- Less than symbol -->
  &gt;    <!-- Greater than symbol -->
  &amp;   <!-- Ampersand symbol -->
  &quot;  <!-- Double quote symbol -->
</TextBlock>

<!-- Display miscellaneous special characters -->
<TextBlock>
  Cæsar   <!-- AE dipthong symbol -->
  © 2006  <!-- Copyright symbol -->
  Español <!-- Tilde symbol -->
  ¥       <!-- Yen symbol -->
</TextBlock>