在文本块文本 WPF 中使用 &
Using & in textblock text WPF
当我在 WPF 文本框中添加硬编码文本时,我发现添加“&”符号有困难。我想知道为什么会这样。有人有原因和解决方案吗?
<TextBlock Text="Shipping & handling"></TextBlock>
我的错误是
错误:需要以下标记:“;”。
使用 &
而不是 &
因此您的代码将如下所示:
<TextBlock Text="Shipping & handling"></TextBlock>
XAML uses character entities defined in XML for special characters.
This topic describes some specific character entities and general
considerations for other XML concepts in XAML.Most character entities
and escape sequences that are typically used to write XAML markup are
defined by XML. This topic does not provide the complete list of these
entities; a detailed reference for the entities can be found in
external documentation, such as in XML specifications. However, for
convenience, this topic lists some of the specific XML character
entities that are typically used in XAML markup.
Following are some of them:
XAML 是有效的 XML 并且你不能在 XML 中使用 & 而不转义它
使用 &(remove space) 而不是 &。
来自维基百科:
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(remove space & use):
•& amp; → & (ampersand, U+0026)
•& lt; →
< (less-than sign, U+003C)
•& gt;→ > (greater-than sign, U+003E)
•& quot; → " (quotation mark, U+0022)
•& apos; → ' (apostrophe, U+0027)
当我在 WPF 文本框中添加硬编码文本时,我发现添加“&”符号有困难。我想知道为什么会这样。有人有原因和解决方案吗?
<TextBlock Text="Shipping & handling"></TextBlock>
我的错误是 错误:需要以下标记:“;”。
使用 &
而不是 &
因此您的代码将如下所示:
<TextBlock Text="Shipping & handling"></TextBlock>
XAML uses character entities defined in XML for special characters. This topic describes some specific character entities and general considerations for other XML concepts in XAML.Most character entities and escape sequences that are typically used to write XAML markup are defined by XML. This topic does not provide the complete list of these entities; a detailed reference for the entities can be found in external documentation, such as in XML specifications. However, for convenience, this topic lists some of the specific XML character entities that are typically used in XAML markup. Following are some of them:
XAML 是有效的 XML 并且你不能在 XML 中使用 & 而不转义它
使用 &(remove space) 而不是 &。
来自维基百科:
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(remove space & use):
•& amp; → & (ampersand, U+0026)
•& lt; → < (less-than sign, U+003C)
•& gt;→ > (greater-than sign, U+003E)
•& quot; → " (quotation mark, U+0022)
•& apos; → ' (apostrophe, U+0027)