c# – How to add comments into a Xaml file in WPF?

c# – 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 cant put comments inside of another tag. Other than that, the syntax youre using is correct.

<UserControl xmlns=...>
    <!-- Heres a valid comment. Notice its outside the <UserControl> tags 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>

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

c# – How to add comments into a Xaml file in WPF?

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

Leave a Reply

Your email address will not be published.