TheBlueSky
TheBlueSky

Reputation: 5948

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

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

Upvotes: 9

Views: 1080

Answers (2)

sll
sll

Reputation: 62544

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\"

Upvotes: 3

Appleman1234
Appleman1234

Reputation: 16106

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.

Upvotes: 0

Related Questions