Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to subscribe to change DependencyProperty? [duplicate]

Possible Duplicate:
Listen to changes of dependency property

Excuse me for my English.

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.

Like this:

MyClass obj = new MyClass();
obj.Subscribe(TextBox.TextProperty, myTextBox);

How can I do this?

like image 299
Kovpaev Alexey Avatar asked Dec 13 '11 00:12

Kovpaev Alexey


1 Answers

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)
 {
     ...
 }
like image 84
Marty Avatar answered Oct 05 '22 00:10

Marty