Skip to main content

Microsoft Silverlight

DesignerProperties.GetIsInDesignMode returns false in Visual StudioRSS Feed

(0)

shacktoms
shacktoms

Member

Member

185 points

149 Posts

DesignerProperties.GetIsInDesignMode returns false in Visual Studio

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.

shacktoms
shacktoms

Member

Member

185 points

149 Posts

Re: DesignerProperties.GetIsInDesignMode returns false in Visual Studio

Still broken in the released Silverlight 2.

shacktoms
shacktoms

Member

Member

185 points

149 Posts

Re: DesignerProperties.GetIsInDesignMode returns false in Visual Studio

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
notacat

Member

Member

77 points

14 Posts

Re: Re: DesignerProperties.GetIsInDesignMode returns false in Visual Studio

Look at DesignerProperties.IsInDesignTool, it returns correct value for me.

shacktoms
shacktoms

Member

Member

185 points

149 Posts

Re: DesignerProperties.GetIsInDesignMode returns false in Visual Studio

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.
 

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities