Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

DesignerProperties.GetIsInDesignMode returns false in V... RSS

4 replies

Last post Jun 08, 2009 02:49 PM by shacktoms

(0)
  • shacktoms

    shacktoms

    Member

    185 Points

    155 Posts

    DesignerProperties.GetIsInDesignMode returns false in Visual Studio

    Oct 02, 2008 03:48 AM | LINK

    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

    185 Points

    155 Posts

    Re: DesignerProperties.GetIsInDesignMode returns false in Visual Studio

    Oct 14, 2008 09:05 PM | LINK

    Still broken in the released Silverlight 2.

  • shacktoms

    shacktoms

    Member

    185 Points

    155 Posts

    Re: DesignerProperties.GetIsInDesignMode returns false in Visual Studio

    Jun 02, 2009 04:41 PM | LINK

    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

    81 Points

    17 Posts

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

    Jun 06, 2009 09:05 PM | LINK

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

  • shacktoms

    shacktoms

    Member

    185 Points

    155 Posts

    Re: DesignerProperties.GetIsInDesignMode returns false in Visual Studio

    Jun 08, 2009 02:49 PM | LINK

    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.