views:

17

answers:

1

I'm using the MVVM pattern to create a WPF standalone application. My program compiles in Visual Studio 2008, but I frequently get warnings in the editor for my DataTemplates.

In my MainWindow.xaml, I've defined the following DataTemplate:

    <DataTemplate DataType="{x:Type ViewModels:TagViewModel}">
        <Views:TagView />
    </DataTemplate>

Where "TagView" is derived from a Page, rather than an ordinary UserControl.

This causes the following message to appear every time I reload the designer in Visual Studio: "Could not create an instance of type 'TagView'. Yet the solution compiles fine and the program seems to work properly.

Is this a bug in the Visual Studio 2008 editor? Or am I doing something wrong?

+1  A: 

You certainly can do that, and the fact that it works in your program is a clear enough demonstration. When the designer cannot create an instance, it usually means there is some code in the constructor that it fails on- perhaps some uninitialized singletons or something of that sort. Look at the constructor code carefully and see if there are any dependencies that would not hold up in the designer.

Charlie
Thanks, Charlie. You're right; it nothing to do with TagView being derived from Page. It was something I was doing within the TagView control itself. I've asked a more specific followup question here: http://stackoverflow.com/questions/3010923/can-the-mvvm-light-viewmodellocator-be-used-in-nested-viewmodels
dthrasher