What if WPF Window does not recognize user controls defined in one project?

I have an “Operation” window in XAML that uses the “Status” user control defined in the same project. When I create a solution, it returns to normal, but when I open the view for the window, the visual studio says: “Failed to 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> 

xmlns:tci is the namespace in which the Status Usercontrol is located. And tci:Status highlighted in blue when this error occurs. How to use UserControl like this?

+4
source share
5 answers

I constantly ran into this problem with one control in my project and tore it up, changing all my images to DynamicResource , not StaticResource .

It is really strange that the designer worked perfectly for the control itself and showed the images as expected. Only when I used the control in my main window did the designer give me the message "Could not create instance."

+2
source

I don’t know exactly what this solution is, but it happens to me from time to time too. I end up deleting the namespace declaration by rebuilding and trying again.: \

+1
source

Try to clear the entire project, and then do a complete rebuild. The WPF designer in VS doesn’t work well, in my opinion, and there are such strange problems like this everywhere.

I recommend not relying on Design View for anything, at the moment - it is too unstable. Try Expression Blend, it's a little better with such things. If you do not want to go along this route, you are probably better off building and running the application: - (

If you are using VS 2008, do you have SP1 installed?

+1
source

Similar to what John Norton said, I also found this link (link removed, see below), which implies resources. I had the situation described in the link and John fixed it.

EDIT

Sorry, now a login is required for communication, and the page no longer exists. I could not find what was supposed to be in three years.

+1
source

I usually see this when I did not create a control. Make sure you create the control and see if everyone sees the problem. Sometimes VS is just confused, and you need to close and open the control you are facing. In this case, it will be your window.

0
source

All Articles