How to add comments into a Xaml file in WPF? How to add comments into a Xaml file in WPF? wpf wpf

How to add comments into a Xaml file in WPF?


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>


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


You can't insert comments inside 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 -->