#121 – Being Notified When the Value of a Dependency Property Changes(属性值改变通知)
来源:互联网 发布:win10广告屏蔽软件 编辑:程序博客网 时间:2024/06/07 05:30
原文地址:https://wpf.2000things.com/2010/11/10/121-being-notified-when-the-value-of-a-dependency-property-changes/
一个应用了依赖属性的类可以选择当属性值发生改变的时候发出通知。要实现通知,该类在注册属性的时候要指定一个PropertyChangedCallback。
PropertyMetadata ageMetadata = new PropertyMetadata( 18, // Default value new PropertyChangedCallback(OnAgeChanged), // ** call when property changes new CoerceValueCallback(OnAgeCoerceValue)); // Register the propertyAgeProperty = DependencyProperty.Register( "Age", // Property's name typeof(int), // Property's type typeof(Person), // Defining class' type ageMetadata, // Defines default value & callbacks (optional) new ValidateValueCallback(OnAgeValidateValue)); // validation (optional)
该类可以使用回调函数在属性值发生改变的时候执行一些逻辑操作,例如自动给其他属性赋值。
private static void OnAgeChanged (DependencyObject depObj, DependencyPropertyChangedEventArgs e){ Person p = (Person)depObj; p.AARPCandidate = (int)e.NewValue > 60 ? true : false;}
0 0
- #121 – Being Notified When the Value of a Dependency Property Changes(属性值改变通知)
- #120 – Clearing a Dependency Property Value(清除依赖属性的值)
- #146 – Use GetValueSource Method to Find the Source of a Dependency Property Value
- #158 – When to Create a Custom Dependency Property(哪些情况要创建自定义依赖属性)
- #147 – Use SetCurrentValue When You Want to Set A Dependency Property Value from Within a Control
- #122 – Validating a Dependency Property(验证依赖属性)
- #123 – Coercing a Dependency Property(强制转换依赖属性的值)
- The experience of Dai ZhenYu when he prepared for being a postgraduate of Tsinghua University
- How to get a notification from Linux when the set of network interfaces changes
- #117 – Registering a Dependency Property(注册一个依赖属性)
- #159 – Creating a Read-Only Dependency Property(创建一个只读的依赖属性)
- #160 – Be Careful When Setting Dependency Property Values from a DependencyObject Constructor
- #167 – Implementing a Dependency Property That Is A Collection(实现一个Collection类型的依赖属性)
- #116 – Dependency Property Values Are Stored in the DependencyObject(依赖属性存储在DependencyObject中)
- #128 – Using Code Snippets to Implement a Dependency Property(用代码段实现依赖属性)
- WPF中的依赖属性(Dependency Property)
- Dependency Property 依赖属性
- 依赖属性Dependency Property
- jdk8内存参数解析与修改(新的参数)
- js正则表达式?:
- nginx php-fpm设置
- 阿里云分布式缓存OCS与DB之间的数据一致性
- 通信接口
- #121 – Being Notified When the Value of a Dependency Property Changes(属性值改变通知)
- 禁止DatePickerDialog弹出键盘
- safari打开的页面数字识别变为蓝色
- 数据预处理系列:(十一)用核PCA实现非线性降维
- 从git库中导出项目
- UIKit框架各个类的简要说明
- 安装hadoop2.5.2插件
- UITableView的style的区别与用法,以及分割线的显示与隐藏
- vmware workstation 12 序列号