There are numerous ways of handling design-time data in view-models. While some people use complex dependency injection frameworks or inversion of control containers, the simplest method is to just check the DesignerProperties.IsInDesignTool flag. Unfortunately this has the side effect of embedding the design-time data into one’s application. Jeremy Likness offers a couple ways of working around this.

His first proposal is the use of partial methods and compiler constants. If the partial method that loads the data, named _WireDesignerData in his example, is excluded from the release build then any calls to it will also be removed.

Another option is the Conditional attribute. This has the same net effect, but doesn’t require the use of partial classes and #if blocks to remove the design-time code.

Tell us what you think

I can't say that I have a favorite strategy. There is no really good way to handle this problem. Design-time data *should* be handled transparently by the tooling and/or by your MVVM framework of choice, with no need to write any additional code. This is important for maintenance *and* extensibility reasons. If you take Jeremy's approach, you end up with a ton of code you have to maintain, which exists soley to support the strategy of a tool, which may or may not work the same in the next version. This problem exists solely because the Expression Blend team is a very closed group and has, at least in my case, blatantly refused to discuss necessary improvements in tooling around this issue. I'm a Silverlight MVP and a Silverlight Insider, and if I can't even get them to have a conversation with me on this subject (I've been trying for two years), that's a real problem. Changes to their tooling to improve the situation are relatively simple, but they aren't interested.

As a side note, the issue of IoC is (or should be) completely orthogonal to design-time data issues. IoC is critical for the decomposition of a complex UI and for the long-term maintenance and extensibililty plan. You should not have to trade off building a good app, just so you can get a tool to show decent values in a text box at design-time.

Sorry if this sounded like a rant, but this question highlights a problem that which has nothing to do with building good software. It's a problem that was created by Microsoft and thrust on the developer; and it's a problem they refuse to engage experienced members of the community on. None of this should be an issue.

Is your profile up-to-date? Please take a moment to review and update.

Email Address

Note: If updating/changing your email, a validation request will be sent

Company name:

Keep current company name

Update Company name to:

Company role:

Keep current company role

Update company role to:

Company size:

Keep current company Size

Update company size to:

Country/Zone:

Keep current country/zone

Update country/zone to:

State/Province/Region:

Keep current state/province/region

Update state/province/region to:

Subscribe to our newsletter?

Subscribe to our architect newsletter?

Subscribe to our industry email notices?

You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.

We notice you're using an ad blocker

We understand why you use ad blockers. However to keep InfoQ free we need your support. InfoQ will not provide your data to third parties without individual opt-in consent. We only work with advertisers relevant to our readers. Please consider whitelisting us.