How to sign up for a DependencyProperty change notification

I have a static dependency property, and I need to know when its value changes, so I can call the callback and update the else value where. Right now I cannot do this because the callback is not static, but a dependency change event.

It currently works when the LostFocus event occurs, but I would prefer it to connect to it whenever a change occurs.

+7
source share
2 answers

A notification of a change in the dependency property takes place in the object. You can use this to map to a non-static variable:

static void OnThePropChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) { YourClass instance = (YourClass)obj; instance.ThePropChanged(args); // Call non-static // Alternatively, you can just call the callback directly: // instance.CallbackMethod(...) } // This is a non-static version of the dep. property changed event void ThePropChanged(DependencyPropertyChangedEventArgs args) { // Raise your callback here... } 
+16
source

You can also configure the binding between your DependencyProperty and "elsewhere" if it comes to getting the value somewhere else.

+1
source

All Articles