我在网上找到这个语法,但是它报错了:
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
<!-- Cool comment -->
xmlns:System="clr-namespace:System;assembly=mscorlib"
'名称不能以字符'<'开头,十六进制值为0x3C。 第4行,第5个位置。' XML无效。
我假设那些XAML命名空间声明在你控件的父标签中?你不能在另一个标签内放置注释。除此之外,你使用的语法是正确的。
<UserControl xmlns="...">
<!-- Here's a valid comment. Notice it's outside the <UserControl> tag's braces -->
[..snip..]
</UserControl>
我发现了Laurent Bugnion的一个不错的解决方案,它看起来可能是这样的:
<UserControl xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:comment="Tag to add comments"
mc:Ignorable="d comment" d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Button Width="100"
comment:Width="example comment on Width, will be ignored......">
</Button>
</Grid>
</UserControl>
这是链接地址: http://blog.galasoft.ch/posts/2010/02/quick-tip-commenting-out-properties-in-xaml/
评论区提供了一些额外的字符来替代高亮显示以注释掉XAML中的属性:
mc:Ignorable=”ØignoreØ”
您不能在XML标记内插入注释。
错误的示例
<Window xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
<!-- Cool comment -->
xmlns:System="clr-namespace:System;assembly=mscorlib">
好的
<Window xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:System="clr-namespace:System;assembly=mscorlib">
<!-- Cool comment -->
小技巧:
在Visual Studio中要注释一段文本,你可以先选中想要注释的文本,然后使用Ctrl + K,接着按Ctrl + C。要取消注释,可以使用Ctrl + K,接着按Ctrl + U。
您不能在UWP XAML标签中放置注释。您的语法是正确的。
待办事项:
<xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:System="clr-namespace:System;assembly=mscorlib"/>
<!-- Cool comment -->
不要做:
<xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
<!-- Cool comment -->
xmlns:System="clr-namespace:System;assembly=mscorlib"/>
对于任何学习这方面的人来说,注释更为重要。因此,在Xak Tacit的想法(来自User500099的link)的基础上,针对单个属性添加注释,请将以下代码添加到XAML代码块的顶部:
<!--Comments Allowed With Markup Compatibility (mc) In XAML!
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ØignoreØ="http://www.galasoft.ch/ignore"
mc:Ignorable="ØignoreØ"
Usage in property:
ØignoreØ:AttributeToIgnore="Text Of AttributeToIgnore"-->
接着在代码块中
<Application FooApp:Class="Foo.App"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ØignoreØ="http://www.galasoft.ch/ignore"
mc:Ignorable="ØignoreØ"
...
AttributeNotToIgnore="TextNotToIgnore"
...
...
ØignoreØ:IgnoreThisAttribute="IgnoreThatText"
...
>
</Application>