Why can't I comment attributes in XAML?

Though you can't comment out using the basic XAML markup, you can achieve the desired results by importing the Open XML markup namespace.

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ignore="http://www.galasoft.ch/ignore"
mc:Ignorable="ignore"

<Label x:Name="Gaga"
       FontSize="20"
       ignore:Content="{Binding SomethingThatIsEmptyAtDesignTime}"
       Content="LookAtMe!"
/>

This blog post describes how to do it.


short answer: because a < char is not allowed between < and > (by XML definition).

The next question should be "How can I comment out an XML/XAML attribute"

The solution (e.g. in MS Blend/Visual Studio) is an mc:Ignorable attribute.

<RootElement
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    mc:Ignorable="d" 
    d:DataContext="this is an attribute for design time only"
>

So if you want to comment out, simply add d: prefix to the attribute

To be more usefull you can have more as one ignorable prefix:

<RootElement
    xmlns   ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x ="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:d ="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:rem ="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:TODO ="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:DISABLED ="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:NOTE ="http://schemas.microsoft.com/expression/blend/2008"
    mc:Ignorable="d rem TODO DISABLED NOTE" 
    d:Foo="this is ignored (design time only attribute)"
    rem:Background="this is also ignored (commented out)"
    TODO:Background=" (commented as TODO)"
    DISABLED:Background="this is also ignored (commented as DISABLED)"
>

The "tokens" rem TODO DISABLED NOTE are only suggestion of me and any other (valid xml names) are possible.

practical sample in any element:

<TextBox
    DISABLED:Background="#FF000000"  NOTE:Background="temporary disabled"
    Background="#FFFFFF"             TODO:Background="specify an other background"
    TODO:TextBox="complete the textbox"
>

Usage of unicode chars:

The following list of unicode chars are valid for xml name:

ǀ ǁ ǂ ǃ

<TextBox
    ǃ:Background="temporary disabled"
    ǂ:Background="temporary disabled"
    ǁ:Background="temporary disabled"
>

Usage as documentation (XML comments)

<RootElement
    ...
    xmlns:doc="http://schemas.microsoft.com/expression/blend/2008"
    mc:Ignorable="... doc ..." 

    <MyControl
        doc.summary="shows my control"
        doc.remarks="any remarks..."
    />
>

Because XAML is XML-based, and XML doesn't allow comments inside other markup. It's unfortunate, I agree; XML commenting leaves much to be desired.