<< Introduction
Observable lists >>
Chapter 1
INotifyPropertyChanged, BaseNotifyPropertyChanged and Notificator

INotifyPropertyChanged is a class residing in System.ComponentModel. This interface only provides one single delegate.

public event PropertyChangedEventHandler PropertyChanged

while BaseNotifyPropertyChanged is nothing but simple System.Object derivate implementing INotifyPropertyChanged interface and providing one additional method

public void OnPropertyChanged (string PropertyName)

and this is everything one needs to know about notifications. Simple class like:

public class MyClass : BaseNotifyPropertyChanged
{
private string myProperty = "";
public string MyProperty {
get {return (myProperty); }
set {
if (myProperty.Equals(value))
return;
myProperty = value;
OnPropertyChanged ("MyProperty");
}
}
}

IMPORTANT!!!
This is already enough to make your new class data aware. Two simple things which one needs to consider when creating data aware properties are:

1) Always check if assigned value is different, checking is much lighter on your software than annoucing non sense change. If value wouldn't change then this is probably the last thing one is interested in.

2) Call OnPropertyChanged after change has been made. This invokes all notifications needed for all interested parties to be notified about this change. And since DataBinding is automatically connected after you specify mapping and DataSource it also executes all needed functionality.
NOTE!!!
Property name is not even needed to be specified in OnPropertyChanged. All tests concluded showed only bad things while System.Data.Bindings were checking for specific property change so sometimes during 0.98 change was adopted to always post message for complete object
- Calculated read only properties were not updated in clients
- Much larger strain on CPU as string comparision is not really ultra light operation


Now... what if INotifyPropertyChanged is impossible for whatever reason (example, class residing outside of your code which you can't override)? Simple...

System.Data.Bindings.Notificator.ObjectChangedNotification (ObjectThatChanged)

and everybody is notified about that change just as that class would provide INotifyPropertyChanged as default OnPropertyChanged actually calls exactly the same. If one is using Notificator from inside class then he can simply pass this as reference. Drawback in this approach is simply in the fact neither you nor System.Data.Bindings don't know if someone is listening or not, it always tries to notify adaptors. With INotifyPropertyChanged on the other hand clients register in PropertyChanged and you could tell anytime how many there are registered in your own INotifyPropertyChanged implementation if needed by simply checking Length of PropertyChanged event.

As far as simple classes are taken into consideration with data binding... this is it. Nothing less, nothing more.

Creation of data class in simple steps...
1) Implement INotifyPropertyChanged or derive from BaseNotifyPropertyChanged
2) Check if new value neing assigned is not the same as already assigned
3) Call OnPropertyChanged after assigning new value


<< Introduction
Observable lists >>