Click here to Skip to main content
Click here to Skip to main content

Tagged as

Detect Design Time Mode in Silverlight

, 27 Feb 2010
Rate this:
Please Sign up or sign in to vote.
In order to detect whether your application is executing in a designer you can either use the GetIsInDesignMode method of DesignerProperties,or the Dependency Property metadata directly like so:C#:bool designTime = (bool)DesignerProperties.IsInDesignModeProperty.GetMetadata( ...
In order to detect whether your application is executing in a designer you can either use the GetIsInDesignMode method of DesignerProperties,
or the Dependency Property metadata directly like so:
 
C#:
bool designTime = (bool)DesignerProperties.IsInDesignModeProperty.GetMetadata(
    typeof(DependencyObject)).DefaultValue
VB.NET:
dim designTime as Boolean = CBool(DesignerProperties.IsInDesignModeProperty.GetMetadata( _ 
GetType(DependencyObject)).DefaultValue
 
This can be then rolled into a static class like so:
C#:
public static class DesignTimeEnvironment
{
    static bool? designTime;
    public static bool DesignTime
    {
        get
        {
            if (!designTime.HasValue)
            {
                designTime = (bool)DesignerProperties.IsInDesignModeProperty.GetMetadata(
                      typeof(DependencyObject)).DefaultValue;
            }
            return designTime.Value;
        }
    }
}
 

VB.NET:
Public Class DesignTimeEnvironment
    Public Shared ReadOnly Property DesignTime As Boolean
        Get
            If Not DesignTimeEnvironment.designTime.HasValue Then
                DesignTimeEnvironment.designTime = New Boolean?(CBool( _ 
                   DesignerProperties.IsInDesignModeProperty.GetMetadata( _ 
GetType(DependencyObject)).DefaultValue))
            End If
            Return DesignTimeEnvironment.designTime.Value
        End Get
    End Property
    Private Shared designTime As Boolean?
End Class

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Daniel Vaughan
President Outcoder
Switzerland Switzerland
Daniel Vaughan is a Microsoft MVP and cofounder of Outcoder, a Swiss software and consulting company dedicated to creating best-of-breed user experiences and leading-edge back-end solutions, using the Microsoft stack of technologies--in particular WPF, WinRT, and Windows Phone.
 
Daniel is the author of Windows Phone 7.5 Unleashed and Windows Phone 8 Unleashed, both published by SAMS.
 
Daniel is also the creator of a number of open-source projects, including Calcium SDK, and Clog.
 
Would you like Daniel to bring value to your organisation? Please contact

Daniel's Blog | MVP profile | Follow on Twitter
 
Windows Phone Experts
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
GeneralReason for my vote of 1 offff Pinmemberseckinkiran26-Jan-12 3:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140814.1 | Last Updated 27 Feb 2010
Article Copyright 2010 by Daniel Vaughan
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid