如何添加评论到WPF中的Xaml文件?

我使用这个语法,因为我在网上find,但它会引发一个错误:

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" <!-- Cool comment --> xmlns:System="clr-namespace:System;assembly=mscorlib" 

'名称不能以'<'字符开头,hex值为0x3C。 第4行,第5位。 XML无效。

我假设这些XML名称空间声明在您的控件的父标记中? 你不能把注释放在另一个标签里面。 除此之外,你使用的语法是正确的。

 <UserControl xmlns="..."> <!-- Here's a valid comment. Notice it's outside the <UserControl> tag's braces --> [..snip..] </UserControl> 

Laurent Bugnion发现了一个很好的解决scheme,它可以是这样的:

 <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 : //geekswithblogs.net/lbugnion/archive/2010/02/01/quick-tip-commenting-out-properties-in-xaml.aspx

你不能在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。