简短回答:因为< 和> 之间不允许使用< 字符(根据XML 定义)。
下一个问题应该是“我怎样才能注释掉一个 XML/XAML 属性”
解决方案(例如在 MS Blend/Visual Studio 中)是 mc:Ignorable 属性。
<RootElement
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DataContext="this is an attribute for design time only"
>
从 VS2015+ 开始,仅支持特定属性,但请阅读下文...
为了更有用,您可以将更多作为一个可忽略的前缀:
<RootElement
xmlns ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x ="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d ="http://schemas.microsoft.com/expression/blend/2008"
xmlns:rem ="ignorable"
xmlns:TODO ="ignorable"
xmlns:DISABLED ="ignorable"
xmlns:NOTE ="ignorable"
mc:Ignorable="d rem TODO DISABLED NOTE"
rem:Background="this is also ignored (commented out)"
TODO:Background=" (commented as TODO)"
DISABLED:Background="this is also ignored (commented as DISABLED)"
>
“令牌”remTODODISABLEDNOTE 只是我的建议,任何其他(有效的 xml 名称)都是可能的。
任何元素的实际示例:
<TextBox
DISABLED:Background="#FF000000" NOTE:Background="temporary disabled"
Background="#FFFFFF" TODO:Background="specify an other background"
TODO:TextBox="complete the textbox"
>
unicode 字符的使用:
以下 unicode 字符列表对 xml 名称有效:
ᆞᅳǀǁǂǃᅀ
<TextBox
ǃ:Background="temporary disabled"
ǂ:Background="temporary disabled"
ǁ:Background="temporary disabled"
>
用作文档(XML cmets)
<RootElement
...
xmlns:doc="ignorable"
mc:Ignorable="... doc ..."
<MyControl
doc.summary="shows my control"
doc.remarks="any remarks..."
/>
>
更新适用于 VS 2015 及更高版本
以上示例已更新
因为命名空间xmlns:d="http://schemas.microsoft.com/expression/blend/2008"现在已经被VS验证了,所以你只能对定义的成员使用它。
但是您可以指定自己的命名空间,例如xmlns:rem="ignorable" 和使用前缀 rem 或任何其他用户定义的前缀来制作没有 VS 设计器错误的 cmets。
使用 VS 2019 测试