How to add comments into a Xaml file in WPF?

Joan Venge picture Joan Venge · Oct 27, 2011 · Viewed 172.8k times · Source

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.

Answer

Dan J picture Dan J · Oct 27, 2011

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>