zoukankan      html  css  js  c++  java
  • When use registerReadonly

    使用:

    internal static readonly DependencyPropertyKey AquariumSizeKey = DependencyProperty.RegisterReadOnly(
      "AquariumSize",
      typeof(double),
      typeof(Aquarium),
      new PropertyMetadata(double.NaN)
    );
    public static readonly DependencyProperty AquariumSizeProperty =
      AquariumSizeKey.DependencyProperty;
    public double AquariumSize
    {
      get { return (double)GetValue(AquariumSizeProperty); }
    }


    通常将DependencyPropertyKey作为internal, 然后expose一个public dependency properpty ,然后写上get ,使其能在xaml使用。

    一个典型应用是在style中trigger这个property, 而不用设置,这个property.

    设置这个property则应该使用一个安全的内部方法:
    /// <summary>
            /// Provides a secure method for setting the AquariumSize property. 
            /// This dependency property indicates whether the Dialog is open.
            /// </summary>
            /// <param name="value">The new value for the property.</param>
            protected void SetAquariumSize (bool value)
            {
                SetValue(AquariumSizeKey , value);
            }

    比如:IsDialogOpen Read-Only Dependency Property

  • 相关阅读:
    php 23种设计模型
    PhpStrom 常用的插件
    PhpStrom 好用的代码小地图插件
    php 23种设计模型
    phpstrom怎样显示类的方法或函数列表
    超好用的谷歌助手插件
    PhpStrom 好用的翻译插件
    php 23种设计模型
    【java】匿名对象
    【java】类的初识
  • 原文地址:https://www.cnblogs.com/liangouyang/p/1335787.html
Copyright © 2011-2022 走看看