Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug DesignerProperties.GetIsInDesignMode returns false in Visual Studio
4 replies. Latest Post by shacktoms on June 8, 2009.
(0)
shacktoms
Member
185 points
149 Posts
10-01-2008 11:48 PM |
I have already reported this bug on the Visual Studio site, but it caused me to scratch my head for a while, so I thought I would post it here as well.
While designing in VisualStudio, DesignerProperties.GetIsInDesignMode(Application.Current.RootVisual) returns false.
As a workaround, you can check if Application.Current.RootVisual is a Canvas. While running live it is generally either null (before the Page constructor has finished) or it is a Page (which is usually derived from UserControl). But when designing, in either Visual Studio or Blend, it is a Canvas.
Note that, in Blend, DesignerProperties.GetIsInDesignMode(Application.Current.RootVisual) returns true.
10-14-2008 5:05 PM |
Still broken in the released Silverlight 2.
06-02-2009 12:41 PM |
Also still broken in Silverlight 3 beta.
I found a better workaround. The thing to do is to ignore the buggy, and strangely implemented, DesignerProperties.GetIsInDesignMode and instead implement a static class with a boolean (e.g. GlobalState.IsDesignMode) , that is initialized to true. Then, near the beginning of in the Application_Startup method in App.xaml.cs, add
GlobalState.IsDesignMode = HtmlPage.Document.QueryString.ContainsKey("debugDesignMode");
Since Application_Startup doesn't run in design mode, GlobalState.IsDesignMode will remain at its initialized value of true, but when the application actually runs, it will be set to false very early on, before the Page is instantiated (unless you specify ?debugDesignMode in the URL, which will allow you to debug your design mode behavior with Visual Studio breakpoints).
This workaround is better because it doesn't depend on some of the quirky behavior in Visual Studio and it also works for Blend.
notacat
77 points
14 Posts
06-06-2009 5:05 PM |
Look at DesignerProperties.IsInDesignTool, it returns correct value for me.
06-08-2009 10:49 AM |
It doesn't change the fact that GetIsInDesignMode isn't implemented correctly (in Visual Studio, it works fine in Blend), but it is a good hint. When my application moves to Silverlight 3, I will check it out.
It looks like the setting there can actually be modified by the application, which is a good thing. Eventually it would be nice to have an application-specific design tool, in Silverlight, for my application.