Yesterday I started a thread on the WPF Forum which has turned out to be rather interesting. I won’t go into too much detail about it in this post, but here’s the general gist. Normally the WPF data binding system requires a data object to send out notifications when one of its properties has changed so that the new value can be displayed in the UI. There are three ways to do this:
- Raise a PropertyNameChanged event when a property has been changed (ex. Raise a NameChanged event when the Name property of an object is set).
- Implement INotifyPropertyChanged on the data object and raise its PropertyChanged event when a property is set to a new value.
- Derive the business object’s class from DependencyObject and implement the property as a dependency property. DPs handle all of the change notification work for you.
As described on the thread I discovered an oddity where the new value of a property was appearing in the user interface, even though the data object emitted no property change notifications. The answer to this mystery, as Douglas Stockwell figured out, has to do with the fact that the data binding system uses PropertyDescriptors to set the value of a property on the source object. PropertyDescriptors have built-in value change notifications which they raise when setting a property on an object. The binding system listens for change notifications sent out by PropertyDescriptors and, when they are raised, will update other Bindings which are bound to the same property on the source object.
For more information about this quirky, yet interesting, aspect of the WPF binding system check it out here.