Why ControlBindingsCollection.Add's datasource is an object and not ipropertynotifychanged?

On the method

ControlBindingsCollection.Add Method (String, Object, String, Boolean, DataSourceUpdateMode, Object)

The second parameter is the dataSource, of the type object.

From my testing, this dataSource has to implement the interface IPropertyNotifyChanged, without which the binding will not work.

My question is, why is it that in that method, it takes in an Object for the dataSource, instead of IPropertyNotifyChanged? Is there other ways that one can do the binding without inheriting the IPropertyNotifyChanged?

I've searched the internet but can't find any relevant information.

1 answer

  • answered 2018-02-13 02:43 Reza Aghaei

    INotifyPropertyChanged is just necessary for having two-way data-binding. In cases which you use one-way data-binding, the object doesn't need to implement INotifyPropertyChanged:

    • One-way data-binding: Control changes will push to data source.

    • Two-Way data-binding: In addition to one-way, data source changes will push to control.

    Here is how two-way data-binding works:

    The Binding object, subscribes for ValueChanged event of the PropertyDescriptor of the bound property. The PropertyDescriptor checks if the container object is INotifyPropertyChanged, then will subscribe for its PropertyChanged to raise ValueChanged event. This way, implementing INotifyPropertyChanged will notify the Binding object about the change in data source property value. Then the binding pulls data and will update the bound control property.