The Design Mode Property Redux

Brian in Cider | 6 Comments July 19, 2006

When we were looking at our options for adding a design mode property to WPF, an obvious choice was to add a dependency property to WPF that the designers would use. None of us remotely thought we could get something like that into WPF at this time. WPF ships with Vista, and Vista is down to fixing "level five recall class super double probation bugs". Or something like that. So, Sparkle and Cider knocked our heads together and came up with a late bound way of accessing a dependency property that we would each define in our own applications.

I got some solid feedback when I posted our solution. Nothing quite as strong as, "you're an idiot for doing this", but pretty close. That's one of the tricky things about working on a product designed for software developers. Developers who have shipped software know that shipping sometimes involves compromise, so you rarely get huge "you're an idiot" flames when things aren't quite right. It's great to have customers who are pragmmatic, but it's important to be able to read between the lines and push changes that need to be made.

I brought up our current design mode solution at a Cider architects meeting and we hashed out a better solution. We decided that if we could convince a WPF architect of the value, we'd have a better chance of getting this change into WPF with him at our side. After a quick email volley we had agreement from WPF that this was a good thing to pursue, even if it was very very late.

To better our chances, Cider took on all the costs. I coded the solution in the WPF codebase so we didn't require any dev resources. The Cider team also wrote unit tests, specs and documentation for the feature, so we had all those angles covered too. When we presented this to Vista shiproom, we didn't meet any of the bug bars, but shiproom agreed this was a blocking issue for Cider and needed to get fixed.

So, there you have it. Windows changelist #184261, checked in only yesterday. With this change we have a new class that looks something like the following:

public static class DesignerProperties {
    public static readonly DependencyProperty IsInDesignModeProperty;
    public static bool GetIsInDesignMode(DependencyObject element);
    public static void SetIsInDesignMode(DependencyObject element, bool value);
}

This class lives in PresentationFramework, which is part of WPF. The property inherits, and works in user controls, templates and styles. You can even data or template bind to it in XAML. Designers will set this property and there will never be a need to grovel in the app domain data.

Comments (6) -

Tim Dawson, Thursday, July 20, 2006 at 4:34 AM

I'm glad you were able to get this property in place. The previous solution did seem a bit hack-ish. Design mode is so fundamental these days that I agree a method of determining it should be part of the core framework.

Mike Brown, Friday, July 21, 2006 at 2:59 PM

YES thank you thank you thank you!!

Shawn Chen, Monday, July 31, 2006 at 2:36 AM

In which release can we get to use this new property? thx.

Richard Houltz, Thursday, August 3, 2006 at 3:14 AM

That's the way to do it! I like the way you guys fixed it yourselves before selling the idea to the WPF team. I'll be dwelling in your design-time code  so I like it when you get it right ;)..Just got fluent in Windows Forms 2.0 design-time..puh. And are now trying to keep up on Cider and WPF. Excited about your posts about design-time and WPF and Cider. Keep up the good work !! Thanks again !!

Brian, Tuesday, August 8, 2006 at 8:25 PM

Shawn --
The design mode bit is available in WPF builds >= 5482.  It will be a while before that makes its way to a CTP, though; Cider just picked up the build and needs to make use of the new property.  I would guess (I've been out of the office for a few weeks so a guess is all it is) that we would have this up and running for some future CTP that runs against the RC candidate for Vista.
Comments are closed