Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Jeremy Likness on Clean Design-Time Friendly ViewModels

Jeremy Likness on Clean Design-Time Friendly ViewModels

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