views:

949

answers:

6

I have a window "Operation" in XAML that uses a user control "Status" defined in the same project. When I build the solution, it returns ok, but when I open the design view for the Window, visual studio says "Could not create an instance of type 'Status'. The XAML for the Window "Operation" is below:

<Window x:Class="TCI.Indexer.UI.Operacao"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:tci="clr-namespace:TCI.Indexer.UI.Controles"
    Title=" " MinHeight="550" MinWidth="675" Loaded="Load" ResizeMode="NoResize" WindowStyle="None" WindowStartupLocation="CenterScreen" WindowState="Maximized" Focusable="True">
    <Canvas Name="canv">

        <tci:Status  x:Name="ucStatus"/>
        <Grid Canvas.Top="0" Canvas.Left="0">

            <StackPanel Orientation="Horizontal">
                <!-- Indices -->
                <Label Width="200"/>

            </StackPanel>
        </Grid>
    </Canvas>
</Window>

The xmlns:tci is the namespace where the Status Usercontrol is. And tci:Status becomes underlined in blue when this error happens. How to use a usercontrol like this?

+1  A: 

I don't know exactly whats the solution, but that happens to me too from time to time. I end up deleting declaration of the namespace, rebuilding and trying again. :\

Megacan
Ha, it make sense! I have 4 user controls in 1 namespace. Meybe must be only one declaration of namespace? It working for me.
Kamilos
+1  A: 

Try cleaning your entire project, then do a full rebuild. The WPF designer in VS is poorly done, in my opinion, and there are weird issues like this all over the place.

I recommend not relying on Design View for anything, at this point - it's just too unstable. Try Expression Blend, it's a little bit better with things like this. If you don't want to go that route, you're probably better off building and running your app :-(

If you're running VS 2008, do you have SP1 installed?

unforgiven3
I tend to edit XAML using the source editor in VS2008 - you still get intellisense, but it seems much more stable than the actual XAML Designer.
Andy
A: 

I typically see this when I haven't built the control. Make sure you build the control and see if you still see the problem. Occasionally, VS just gets confused and you need to close and open the control you are having a problem with. In this case, that would be your window.

Ken Wootton
+2  A: 

I was consistently having this problem with one control in my project and wound up resolving it by changing all of my images to DynamicResource rather than StaticResource.

The really strange thing is that the designer worked just fine for the control itself and showed the images as expected. It was only when I used the control inside my main window that the designer gave me the "Could not create instance of " message.

Jon Norton
A: 

Similar to what Jon Norton said, I also found this link (http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=427374) that implicates resources. I had the situation described in the link, and Jon's fix sorted it.

pete the pagan-gerbil
A: 

Same problem, and changing StaticResource to DynamicResource fixed it. Thanks for that tip.

sav