I've found that in many cases the designer in Visual Studio 2010 or in Expression Blend 4 will crash if, for example, a WPF UserControl contains a control does something in code based on the control's loaded event (like transition to a different Visual State via a call like VisualStateManager.GoToState(this, "AfterLoaded", true);
).
My typical approach to solving these designer crashes is use the DesignerProperties.GetIsInDesignMode(this)
approach in the control's contructor:
public MyControl()
{
// prevent designer crashes
if (DesignerProperties.GetIsInDesignMode(this))
return;
Loaded += MyControlLoaded;
Unloaded += MyControlUnloaded;
IsVisibleChanged += MyControlIsVisibleChanged;
}
This approach targets both Visual Studio 2010 and Expression Blend 4 and enables me to have my design surface visible again. However, it also removes any design-time preview that a designer might provide for me (like with the above-mentioned VSM state change on the loaded event). Blend, in particular, is able to provide that preview for me in its designer (if I switch to a different Blend tab and then switch back to the original tab I see the loaded animation run). Furthermore, with some controls that I have not yet applied the above approach to, Visual Studio 2010's designer will crash, while Blend 4's designer will not. Thus what I would like to do is check for only Visual Studio 2010's designer so that I can let Blend's designer pass through and provide its previewing abilities.
The benefit of this ability would be that I save time by not needing to build and run the application as often (to see things like the loaded animation) since Blend's designer could give me its preview.