【发布时间】:2023-03-28 11:35:01
【问题描述】:
我使用了我在网上找到的这种语法,但它会引发错误:
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
<!-- Cool comment -->
xmlns:System="clr-namespace:System;assembly=mscorlib"
'名称不能以'
【问题讨论】:
我使用了我在网上找到的这种语法,但它会引发错误:
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
<!-- Cool comment -->
xmlns:System="clr-namespace:System;assembly=mscorlib"
'名称不能以'
【问题讨论】:
我假设那些 XAML 命名空间声明位于控件的父标记中?您不能将 cmets 放在另一个标签内。除此之外,您使用的语法是正确的。
<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/
链接上的评论者为忽略前缀提供了额外的字符来代替突出显示:
mc:Ignorable=”ØignoreØ”
【讨论】:
-- SGML comment -- 样式适用于内部标记 cmets。但是不,99.44% 的 XAML 解析器不接受 SGML in-tag cmets。
您不能在 xml 标签内插入 cmets。
不好
<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。
【讨论】:
Edit.CommentSelection 和 Edit.UncommentSelection 命令。
您不能将 cmets 放在 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"/>
【讨论】:
对于任何学习这些东西的人来说,cmets 更为重要,因此借鉴 Xak Tacit 的想法
(来自 User500099 的 link)对于 Single Property cmets,将其添加到 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>
【讨论】: