Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Detect Design Time Mode in Silverlight

0.00/5 (No votes)
27 Feb 2010 1  
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#:
C#
bool designTime = (bool)DesignerProperties.IsInDesignModeProperty.GetMetadata(
    typeof(DependencyObject)).DefaultValue

VB.NET:
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#:
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:
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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here