Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add comments into 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" 

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

like image 326
Joan Venge Avatar asked Oct 27 '11 20:10

Joan Venge


People also ask

How add XAML file to WPF?

Just right click the project, choose Add -> Window and that will add a new xaml file along with its corresponding .

How do I comment multiple lines in XAML?

If you are using Eclipse IDE you can comment out lines in an XML file by highlighting them and press Ctrl+Shift+c.

How do you add comments on XAML?

You can add comments to the XAML code that's in the MainWindow. xaml tab in the following ways: Enter <! -- before a comment and then add --> after the comment.


2 Answers

I assume those XAML namespace declarations are in the parent tag of your control? You can't put comments inside of another tag. Other than that, the syntax you're using is correct.

<UserControl xmlns="...">     <!-- Here's a valid comment. Notice it's outside the <UserControl> tag's braces -->     [..snip..] </UserControl> 
like image 165
Dan J Avatar answered Sep 23 '22 19:09

Dan J


Found a nice solution by Laurent Bugnion, it can 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/

A commenter on the link provided extra characters for the ignore prefix in lieu of highlighting:

mc:Ignorable=”ØignoreØ” 
like image 33
user500099 Avatar answered Sep 23 '22 19:09

user500099