How to check if the silverlight application is in design mode?
2010-04-15 11:57 craystall 阅读(350) 评论(0) 收藏 举报As a siverlight control developer, it's very important to know when the silverlight control is in design mode, and then we can design the beautiful design skin for our control. Here is a part of tips:
/// <summary>
/// Provides a custom implementation of DesignerProperties.GetIsInDesignMode
/// to work around an issue.
/// </summary>
internal static class DesignerProperties
{
/// <summary>
/// Returns whether the control is in design mode (running under Blend
/// or Visual Studio).
/// </summary>
/// <param name="element">The element from which the property value is
/// read.</param>
/// <returns>True if in design mode.</returns>
[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)
{
_isInDesignMode =
(null == Application.Current) ||
Application.Current.GetType() == typeof(Application);
}
return _isInDesignMode.Value;
}
/// <summary>
/// Stores the computed InDesignMode value.
/// </summary>
private static bool? _isInDesignMode;
}
The code comes from http://blogs.msdn.com/delay/archive/2009/02/26/designerproperties-getisindesignmode-forrealz-how-to-reliably-detect-silverlight-design-mode-in-blend-and-visual-studio.aspx