zoukankan      html  css  js  c++  java
  • WPF中的DesignMode判断

    WPF中提供你一个类似WinForm的DesignMode属性的方法来判断当前是否处于设计器模式:

        bool IsInDesignMode
        {
            get { return DesignerProperties.GetIsInDesignMode(this); }
        }

    对于非UI对象,要判断是否处于设计器模式,则可以这么使用:

        bool IsInDesignMode
        {
            get { return DesignerProperties.GetIsInDesignMode(new DependencyObject()); }
        }

    但是,这两种方式有时会失效(具体什么情况下会失效不明),这个时候,则可以试一下如下这种方法。

        bool IsInDesignMode
        {
            get
            {
                return (bool)DesignerProperties.IsInDesignModeProperty
                            .GetMetadata(typeof(DependencyObject)).DefaultValue;
            }
        }

    这种方式没有UI线程的限制,感觉也是最稳定的一种方式,平时大可以用这种方式好了。

  • 相关阅读:
    Web 应用的 UML 建模与 .NET 框架开发
    UML类详解
    学习Pythod 有感
    树形结构应用技巧
    面向对象的设计原则-类设计原则
    prototype 学习
    php framework kohana 学习2
    用批命令更新数据库
    HashTable
    jquery 调用wcf project
  • 原文地址:https://www.cnblogs.com/TianFang/p/3329232.html
Copyright © 2011-2022 走看看