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 objec开发者_如何学Ct.
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?
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
If you are using WPF
, you can use DependencyProperty.OverrideMetadata()
to add a value changed callback.
精彩评论