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.
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?
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.
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.
That’s the way its done. VS won’t ever be ‘updated’ as it works as… well, designed.