views:

719

answers:

2

I'm working on some Silverlight controls and I would like to explicitly handle the way they appear in Blend. Specifically, these controls have dependencies that are initialized at runtime, and thus throw exceptions in the designer. But even in the absence of the exception, I would like to make them appear a certain way in Blend.

I know that this is possible with WPF (using myassembly.VisualStudio.Design.dll), but I haven't been able to find info on doing this with Silverlight.

I have seen the hack described here that checks does this:

bool designTime = (System.Windows.Browser.HtmlPage.IsEnabled == false);

I would prefer a more explicit solution though.

+4  A: 

There is an extremely detailed post on how to deal with design time extensibility here. There you will find out how to do the Visual Studio and Blend design time stuff for Silverlight.

Control vendors and people who author custom controls often find themselves wishing they could give a better experience for their custom controls. However, there’s a huge lack of public information on this topic. And I’ve decided to correct this situation with this short 50+ pages article.

Like I said, it's long. :)

Bryant
Perfect! Thanks!
bennage
+2  A: 

The specific attribute to check is DesignerProperties:

using System.ComponentModel.DesignerProperties

if (DesignerProperties.GetIsInDesignMode(this)) { }

where this is a DependencyObject (any visual element).

Michael S. Scherotter
Thanks - it took me so long to ask the right question in google to get this answer... ;-)
Rashack