WPF设计器不会加载实体框架 [英] WPF designer won't load with entity framework

查看:48
本文介绍了WPF设计器不会加载实体框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用实体框架时,让WPF设计器在VS 2008中工作时遇到了真正的问题.我有一个从实体模型获取数据的用户控件.用户控件设计器加载正常,但主窗口引发以下错误无法创建'CampaignList类型的实例".当我编译项目时没有问题.

I have been having real problems getting the WPF designer to work in VS 2008 when i use the entity framework. I have a user control that gets data from an entity model. The user control designer loads fine but the main window throws the following error "Could not create an instance of type 'CampaignList". When i compile the project there is no problem.

我已经开始使用一种变通方法,该方法可以检测到它何时处于设计模式下,而在设计模式下不创建实体"对象.但是,这似乎有点丑陋.有没有更好的方法可以做到这一点,还是我们只需要等待VS进行更新?

I have started using a workaround where i detect when it is in design mode and don't create an "Entities" object when in design mode. However this seems like a bit of an ugly hack. Is there a better way to do this or do we just have to wait for VS to get updated?

推荐答案

这正是您需要做的.它看起来可能像是一个丑陋的hack,甚至可能是一个丑陋的hack,但这正是框架处理设计时渲染的方式.几乎每个标准框架控件(窗体,wpf和web)都确定它是在运行时还是在设计时显示,并且其行为有所不同.这就是基于组件的设计的主要思想.您的类存在于两种不同的环境中-运行时环境和设计时环境,并且它们都应在这两种环境中提供丰富且方便的用户体验.唯一的方法就是让控件作者对控件进行编码.

That's exactly what you need to do. It may seem like an ugly hack, heck it may even be an ugly hack, but that's exactly how the framework handles design time rendering. Almost every standard framework control (forms, wpf, and web) determines if its being displayed at runtime or design time and behaves differently. That's the main idea behind component based design. Your classes exist in two different environments--the runtime environment and the design time environment, and they should offer a rich and convenient user experience in both. And the only way to do this is for the control author to code the control to do it.

最理想的情况是,您将希望在堆栈中尽可能高地处理这种情况.最肯定的是,您将要确定是否在用户控件中进行了设计时限,并将伪数据源替换为实体框架.您将显示在某些数据绑定表单和wpf控件中看到的伪数据类型.

Optimally, you'll want to handle this situation as high up in the stack as possible. Most definitely you'll want to determine if you're in design time up in your user control and substitute a dummy data source for the entity framework. You'll be displaying the kind of fake data you see in some of the databound forms and wpf controls.

这就是它的完成方式.VS永远不会被更新",因为它的工作原理是……精心设计.

That's the way its done. VS won't ever be "updated" as it works as... well, designed.

这篇关于WPF设计器不会加载实体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆