How to add comments to a xaml file in WPF?

I used this syntax as I found online, but it throws an error:

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

'The name cannot begin with the character' <'character, the hexadecimal value is 0x3C. Line 4, position 5. 'XML is not valid.

+57
comments c # wpf xaml
Oct 27 2018-11-11T00:
source share
5 answers

I assume these XML namespace declarations are in the parent tag of your control? You cannot leave comments inside another tag. In addition, the correct syntax is correct.

 <UserControl xmlns="..."> <!-- Here a valid comment. Notice it outside the <UserControl> tag braces --> [..snip..] </UserControl> 
+63
Oct 27 '11 at 20:05
source share
— -

Found a nice solution from Laurent Bugnion, it might look something like this:

 <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> 

Here's the link: http://blog.galasoft.ch/posts/2010/02/quick-tip-commenting-out-properties-in-xaml/

Commenting on the link, added extra characters for the ignore prefix instead of highlighting:

 mc:Ignorable="ØignoreØ" 
+27
Feb 13 '12 at 16:27
source share

You cannot embed comments in xml tags.

Bad

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

Good

 <Window xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:System="clr-namespace:System;assembly=mscorlib"> <!-- Cool comment --> 
+23
Oct. 27 '11 at 20:10
source share

Only tip:

In Visual Studio, to comment on text, you can select the text you want to comment on, then use Ctrl + K and then Ctrl + C. To uncomment, you can use Ctrl + K and then Ctrl + U.

+6
Aug 03 '15 at 16:26
source share

For those who study this material, comments are more important, therefore, relying on the idea of ​​Xak Tacit (from User500099 link ) for Single Property Comments, add this to the top of the XAML code block:

 <!--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"--> 

Then in the code block

 <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> 
0
Dec 26 '17 at 13:25
source share



All Articles