Christopher Bennage
Christopher Bennage

Reputation: 2610

Design-time rendering of Silverlight controls in Expression Blend 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.

Upvotes: 2

Views: 1240

Answers (2)

Michael S. Scherotter
Michael S. Scherotter

Reputation: 10785

The specific attribute to check is DesignerProperties:

using System.ComponentModel.DesignerProperties

if (DesignerProperties.GetIsInDesignMode(this))
{
}

where this is a DependencyObject (any visual element).

Upvotes: 2

Bryant
Bryant

Reputation: 8670

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. :)

Upvotes: 4

Related Questions