views:

767

answers:

3

Okay so I have a Window in WPF. I add the following line inside of it:

xmlns:controls="clr-namespace:mCubed.Controls"

This compiles and runs just fine, but the Visual Studio designer gives me this error:

Could not load file or assembly 'mCubed, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

When I remove this line from the Window, it compiles and runs just fine and the Visual Studio designer works like a charm!

I'm confused as to why that one line breaks the designer? This occurs REGARDLESS if I have put the following line in the body of the XAML document.

<controls:MyControl/>

All my .cs files are in the same VS project. I have a mCubed namespace which contains my cleverly named mCubedWindow class. I have all my controls classes defined in the mCubed.Controls namespace. Do NOT tell me this is an assembly problem, ALL MY FILES ARE IN THE SAME VS PROJECT!

+2  A: 

Not an assembly problem, just a designer problem. The VS WPF designer in 2008 is primitive at best - completely useless IMHO. I turn it off completely and use the XML editor instead. Hopefully things will improve drastically in 2010.

HTH, Kent

Kent Boogaart
+1  A: 

That's a bit weird. I've developed several projects that do exactly that. Here's a quick dummy project, all in one .exe:

First, a UserControl with a couple of buttons:

<UserControl x:Class="WpfApplication1.UserControl1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
    <Grid Width="30">
        <Button HorizontalAlignment="Left">A</Button>
        <Button HorizontalAlignment="Right">B</Button>
    </Grid>
</UserControl>

Now the main window, with my control added to it:

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:p="clr-namespace:WpfApplication1"
    Title="Window1" Height="300" Width="300">
    <Grid>
        <p:UserControl1/>
    </Grid>
</Window>

No error messages anywhere.

Daniel Earwicker
I've put my custom controls into a Controls folder in my project if that makes a difference.
Nick
A: 

It is when you have a custom namespace in a user control that it becomes a problem

Mullany