How To: Stop Visual Studio XAML Editor from Adding mc:Ignorable
Asked Answered
I

2

9

Whenever I run my Windows Phone application while the XAML page is open, Visual Studio adds the following to my XAML:

mc:Ignorable="d" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"   
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
d:DesignHeight="768" 
d:DesignWidth="480"

How can I stop it from doing so? I know it won't hurt me to keep it, but I don't want it in my code unless I need it.

Thanks

Indivisible answered 24/2, 2012 at 5:38 Comment(0)
P
3

When creating any kind of predefined document Visual Studio uses built in default templates.

For instance for Visual Studio 2010 custom template for WPF UserControl looks:

<UserControl x:Class="$rootnamespace$.$safeitemname$"
             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"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>

    </Grid>
</UserControl>

File location at my PC: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplatesCache\CSharp\WPF\1033\WPFUserControl.zip\UserControl1.xaml

So as you can see Microsoft Team decided to include this namespace by default. I believe you can find such template for Windows Phone project as well, just look under the Visual Studio installation folder, and obviously you always can create and use own templates for any kind of document.

And what I found most neat - you do not need to restart Visual Studio in order to pickup template updates you made. I just removed mc:Ignorable from default demplate and tried to create a new UserControl - it was created using just updated template file, so Visual Studio 2010 pick up changes on the fly, this is nice, credits to Microsoft Team.


Looks like all available templates are grouped per Technology/Framework under this folder:

"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplatesCache\CSharp\"

Puss answered 6/4, 2012 at 15:18 Comment(3)
I wasn't talking about the inclusion of mc:Ignorable and friends in my XAML when creating a new file. If you go back and read the question again I mentioned that these are inserted in my XAML everytime I run the application while the page open (and active).Indivisible
Ok and when you stop the application tis tag is still in XAML or get removed automatically as well? I can imagine why Vsual Studio adding this tags, either issue or it is needed to guarantee some state/logic whilst compile/parse XAML, but if VS does not remove this stuff - this is surely a bugPuss
No, it's not getting removed. Those added stuff might be important for the Design view but I almost don't use it... it doesn't make sense to me to have it anyway... but whatever, seems there is no way around it :)Indivisible
C
0

I couldn't find a configuration option or registry that stops Visual Studio XAML Editor adding the mc:Ignorable to a given XAML page.

Possible ways you could stop Visual Studio adding it include:

  • Closing your XAML Page manually before running your application
  • Closing your XAML Page automatically before running your application by extending Visual Studio (resources here) or using macros (macros are removed from Visual Studio 11 and onwards)
  • Setting the editor for editing XAML to just use the regular text editor inside of the XAML Editor. (resources here and here)
  • Removing the added XAML by having your application or post build step edit the XAML file. A partial code snippet is here. If taking the application approach you would need to edit the file and then reload the relevant control. Information on post build events is avaliable at How to: Specify Build Events (C#) and Gotcha! Visual Studio Pre/Post-Build Events for using a batch file.

Whether you need it or not depends on your use case for whether you need the design time width and height specified to Visual Studio's designer, which is your decision. For further information see mc:Ignorable Attribute for the Attribute itself and the following Stackoverflow post for additional information on d:DesignWidth and d:DesignHeight.

Compensation answered 2/4, 2012 at 11:9 Comment(1)
These are lots of hacks and work around. Although I hate when Visual Studio adds that markup to my XAML, I don't thing it worths going through all this hassle :) thanks any way.Indivisible

© 2022 - 2024 — McMap. All rights reserved.