C# 什么';DesignerProperty.IsInDesignMode和DesignerProperty.IsInDesignTool之间的区别是什么?

C# 什么';DesignerProperty.IsInDesignMode和DesignerProperty.IsInDesignTool之间的区别是什么?,c#,wpf,silverlight,C#,Wpf,Silverlight,DesignerProperty使用GetIsInDesignMode(元素)和IsInDesignTool公开两种类似的设计状态 他们之间有什么区别 为什么我要用一个而不是另一个 谷歌快速搜索显示,iIndesignTool似乎适用于Silverlight和ExpressionBlend。因此,也许IsInDesignMode是VS所使用的,但IsInDesignTool是其他VS所需要的。它们是完全相同的东西 IsInDesignTool 如果元素在设计器的上下文中运行,则为true;否则

DesignerProperty
使用
GetIsInDesignMode(元素)
IsInDesignTool
公开两种类似的设计状态

  • 他们之间有什么区别
  • 为什么我要用一个而不是另一个

谷歌快速搜索显示,iIndesignTool似乎适用于Silverlight和ExpressionBlend。因此,也许IsInDesignMode是VS所使用的,但IsInDesignTool是其他VS所需要的。

它们是完全相同的东西

IsInDesignTool
如果元素在设计器的上下文中运行,则为true;否则为false

GetIsInDesignMode(元素)
“元素的IsInDesignMode属性值。”

然而,VisualStudio每次都会失败一次

DesignerProperties.GetIsInDesignMode(this)
所以最好使用

return DesignerProperties.GetIsInDesignMode(this) || DesignerProperties.IsInDesignTool;
如果你不想让它崩溃

Silverlight的.Net反射镜
公共静态bool GetIsInDesignMode(DependencyObject元素)
{
if(元素==null)
{
抛出新的ArgumentNullException(“元素”);
}
布尔标志=假;
if(Application.Current.RootVisual!=null)
{
flag=(bool)Application.Current.RootVisual.GetValue(IsInDesignModeProperty);
}
返回标志;
}
公共静态布尔IsInDesignTool
{
得到
{
返回isInDesignTool;
}
[证券评论]
设置
{
isInDesignTool=值;
}
}
内部静态布尔内部标识模式
{
[编译生成]
得到
{
返回k__BackingField;
}
[编译生成]
设置
{
k__BackingField=值;
}
}

你写的它们完全是一样的,但是,在你回答的其余部分中,没有任何东西支持这种说法。相反,恰恰相反。你从MSDN中的两个小摘录没有提到它们的一致性,反射器片段显示它们的实现没有完全相同的部分。它是斜体的……它们在技术上应该产生相同的结果,但它们的方式不同。你的意思是“理论上它们是相同的东西”
public static bool GetIsInDesignMode(DependencyObject element)
{
    if (element == null)
    {
        throw new ArgumentNullException("element");
    }
    bool flag = false;
    if (Application.Current.RootVisual != null)
    {
        flag = (bool) Application.Current.RootVisual.GetValue(IsInDesignModeProperty);
    }
    return flag;
}


public static bool IsInDesignTool
{
    get
    {
        return isInDesignTool;
    }
    [SecurityCritical]
    set
    {
        isInDesignTool = value;
    }
}

internal static bool InternalIsInDesignMode
{
    [CompilerGenerated]
    get
    {
        return <InternalIsInDesignMode>k__BackingField;
    }
    [CompilerGenerated]
    set
    {
        <InternalIsInDesignMode>k__BackingField = value;
    }
}