如何订阅改变的DependencyProperty? [英] How to subscribe to change DependencyProperty?
本文介绍了如何订阅改变的DependencyProperty?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
听依赖属性修改
Possible Duplicate:
Listen to changes of dependency property
对不起我的英语水平。
我需要创建一个可以订阅改变的DependencyProperty类,并根据此属性的新值来执行某些操作。
I need to create a class that could subscribe to change DependencyProperty, and depending on the new value of this property to perform some action.
这样的:
MyClass obj = new MyClass();
obj.Subscribe(TextBox.TextProperty, myTextBox);
我怎样才能做到这一点?
How can I do this?
推荐答案
下面是做它,使用得心应手DependencyPropertyDescriptor类的一种方式。
Here is one way of doing it, using the handy DependencyPropertyDescriptor class.
var pd = DependencyPropertyDescriptor.FromProperty(TextBox.TextProperty, typeof(TextBox));
pd.AddValueChanged(myTextBox, OnTextChanged);
private void OnTextChanged(object sender, EventArgs e)
{
...
}
这篇关于如何订阅改变的DependencyProperty?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文