BT

New Early adopter or innovator? InfoQ has been working on some new features for you. Learn more

Jeremy Likness on Clean Design-Time Friendly ViewModels

| by Jonathan Allen Follow 140 Followers on Jul 29, 2011. Estimated reading time: less than one minute |

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.

InfoQ Asks: What is your favorite strategy for handling design-time data?

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

No Favorite by Rob Eisenberg

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.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

1 Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT