// (c) Copyright Microsoft Corporation. // This source is subject to the Microsoft Public License (Ms-PL). // Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details. // All other rights reserved. using System.Diagnostics.CodeAnalysis; namespace System.Windows.Controls { /// /// Provides a custom implementation of DesignerProperties.GetIsInDesignMode /// to work around an issue. /// internal static class DesignerProperties { /// /// Returns whether the control is in design mode (running under Blend /// or Visual Studio). /// /// The element from which the property value is /// read. /// True if in design mode. [SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "element", Justification = "Matching declaration of System.ComponentModel.DesignerProperties.GetIsInDesignMode (which has a bug and is not reliable).")] public static bool GetIsInDesignMode(DependencyObject element) { if (!_isInDesignMode.HasValue) { #if SILVERLIGHT _isInDesignMode = (null == Application.Current) || Application.Current.GetType() == typeof(Application); #else _isInDesignMode = System.ComponentModel.DesignerProperties.GetIsInDesignMode(element); #endif } return _isInDesignMode.Value; } /// /// Stores the computed InDesignMode value. /// private static bool? _isInDesignMode; } }