locked
Embedded XAML Comments

    General discussion

  • Hi,

    I was just wondering if there are any plans to allow embedded comments in the WPF designer?

    This 'issue' drives me crazy on an almost daily basis!  When playing with XAML templates and the like, I often comment bits of the template out, temporarily.  This works fine, until I want to comment out a whole section that already contains comments... it's not possible!  I would have to manually remove all the sub-comments, before I can successfully comment out the whole block.  I tend to cut/paste the whole block to notepad and back again when required - a real pain.

    I realise this is due to the fact that XAML is very much like XML and as such, does not allow two adjacent hyphens within a comment (http://msdn.microsoft.com/en-us/library/bb514668.aspx).

    Are there any plans to allow this behaviour in the future?  I'm surprised I couldn't find any other posts regarding this, I'm sure I'm not the only one pulling my hair out over this!


    Regards,
    Dave
    Monday, December 22, 2008 4:32 PM

All replies

  • I suspect most people don't use comments in XAML files at all, let alone nested ones.  There's no way to allow nested XML comments without breaking every single tool in the XAML tool chain, but I suppose Microsoft could introduce a pseudo-element that directs the XAML parser to ignore everything within the paired elements, e.g. <comment>...</comment>.  Such comments could be nested.

    Tuesday, December 23, 2008 11:13 AM
  • A <comment> tag that would be ignored by XAML seems like it would be handy. Not being able to nest comments makes it a bit of a hassle to experiment with enabling/disabling chunks of XAML that has comments. I would certainly use this feature if it were available.



    Saturday, January 03, 2009 3:23 AM
  •  I think every tag in XAML is easy to understand,so it is not necessary to embedded comments in the WPF designer.
    Monday, January 05, 2009 2:39 PM
  • Hi MMHunter,

    I agree, all XAML tags are easy to understand and should not require comments - you can already add comments should you wish and this is all good.

    What I am on about (that Eric stated above) is the ability to temporarily comment sections of actual XAML markup - whilst working out how best to design a window/page.

    The <comment>...</comment> tags would be great, good idea Chris... so long as they could be added/removed by selecting a section of markup and using ctrl+kc / ctrl+ku.  I use this all the time in the code editor - if you select a block of code that already contains some lines that have comments and do ctrl+kc, a second comment mark is added to the start of any line that is already commented.  This way, if you subsequently un-comment the same section, the originally commented lines will still be commented... like a multi-stage undo for commenting lines.

    It is this type of behaviour I would love to see in the XAML editor, which I believe could be possible using the <comment> tag approach (as opposed to adding a 'comment' character to the start of each line - like the code editor does).

    Using the tag approach may also mean the outlining would keep working... another major annoyance to using the <!-- --> tags in the XAML designer is the lack of outlining... e.g. I have just commented out a lengthy resource at the top of a XAML file, as I think there may be a better way to achieve what I want (but don't want to delete the resource until I'm happy it's not required).  Whilst not commented, I get a nice little '-' symbol next to the resource, which allows me to collapse the 100 lines the resource occupies, to just one, allowing me to simply see the rest of the markup below.  Once I comment the resource, all outlining is turned off... I can't now collapse the commented resource; I have to scroll right down to see the rest of the markup!!!  very annoying.

    A bonus would be for the <comment> tags and all text in-between the tags, to be coloured green. 


    Anyone have any thoughts?

    Or does anyone know if Microsoft plans on enhancing the commenting and/or outlining in the XAML designer in the future?

    Regards,
    Dave
    Monday, January 05, 2009 3:13 PM
  • thank you for your wonderful reply!
    Tuesday, January 06, 2009 7:00 AM
  • Hello,
    you can use the markup compatibility mc:Ignorable attribute in your root element:

     

    <Page  
        x:Class="CommentingOut.Page1" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        Title="Page1" 
        xmlns:c="comment" 
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        mc:Ignorable="c" 
        > 
     
        <Grid> 
            <!-- Width attribute ignored --> 
            <StackPanel c:Width="100">  
            </StackPanel> 
          
            <!-- The whole button element is ignored --> 
            <c:Button> 
            </c:Button> 
        </Grid> 
    </Page> 
     
     


    Blend uses the Ignorable attribute to disable its namespace.
    You will have to replace mc:Ignorable="d" with mc:Ignorable="d c".

    mc:Ignorable does not apply to namespace mappings into assemblies so if you want to ignore elements
    from such a namespace you can wrap them in a dummy element <c:Comment></c:Comment>.
    So I guess you already have your comment tag.

    I hope this helps, have a look here for more info:
    http://msdn.microsoft.com/en-us/library/aa350024.aspx

    Monday, February 23, 2009 7:01 PM
  •  How would this work for child elements?

    <c:Grid>
        <Button Content="Click Me" />
    </c:Grid>
    In the example above is the Button also considered a comment as well because it is a child of an element marked with the namespace "c"?
    Wednesday, October 07, 2009 1:25 PM
  • Yes, all this markup will be effectively ignored.

    Wednesday, October 07, 2009 1:27 PM
  • <c:Comment></c:Comment> works great. Thanks.

     


    Saturday, January 22, 2011 11:10 PM
  • simple write <!--> to open and close the comment.

    Best Regards,

    Hen

      <Window.Resources>
        <Style TargetType="{x:Type RadioButton}">
          <Style.Triggers>
            <!-->
            comments
            <!-->
          </Style.Triggers>
        </Style>
      </Window.Resources>
    
    </Window>

    Monday, March 28, 2011 11:56 AM
  •     <Window.Resources>
            <Style TargetType="{x:Type RadioButton}">
                <Style.Triggers>
                    <!-->
                    comments
                    <!-->
                </Style.Triggers>
            </Style>
        </Window.Resources>
    </Window>
    Monday, March 28, 2011 11:57 AM