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


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

<!-- Cool comment -->

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

Best Solution

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