1

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?

Wouter
  • 2,170
  • 1
  • 28
  • 58

2 Answers2

3

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
Gishu
  • 134,492
  • 47
  • 225
  • 308
  • quite handy, but there is no way to not bind to a specific DependencyProperty but any change to the object? – Wouter Dec 15 '10 at 09:52
  • @ Wouter - not unless the object wants you to i.e. exposes an IsChanged or IsDirty property. I do not know of a generic (any)change notification mechanism for arbitrary objects. – Gishu Dec 15 '10 at 10:03
1

If you are using WPF, you can use DependencyProperty.OverrideMetadata() to add a value changed callback.

decyclone
  • 30,394
  • 6
  • 63
  • 80