Search code examples
c#.netdependencyobject

Bind to DependencyProperty in code


I have an object which is derived from DependencyObject with multiple DependencyProperties. This object is a given and I can not add ValueChanged callbacks within this object.

I would like to be notified (in code, not xaml) of any property changes. When an object implements INotifyPropertyChanged you can subscribe to the PropertyChanged event. How does this work for DependencyObjects?


Solution

  • Check out this link

    • If you are exposing the DP, you can specify a Property change callback in the metadata parameter while you're registering the DP.
    • If you are listening to someone else's DP that you don't control, you obtain a DependencyPropertyDescriptor instance and use it to attach your callback