Kov*_*xey 14 .net c# wpf dependency-properties
可能重复:
侦听依赖项属性的更改
对不起我的英语.
我需要创建一个可以订阅更改DependencyProperty的类,并根据此属性的新值来执行某些操作.
像这样:
MyClass obj = new MyClass();
obj.Subscribe(TextBox.TextProperty, myTextBox);
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
Mar*_*ill 28
这是使用方便的DependencyPropertyDescriptor类的一种方法.
var pd = DependencyPropertyDescriptor.FromProperty(TextBox.TextProperty, typeof(TextBox));
pd.AddValueChanged(myTextBox, OnTextChanged);
private void OnTextChanged(object sender, EventArgs e)
{
...
}
Run Code Online (Sandbox Code Playgroud)