开发者

Can a DataTemplate be a Page?

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 t开发者_如何转开发he 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜