<< INotifyPropertyChanged, BaseNotifyPropertyChanged and Notificator
Adaptors - basics >>
Chapter 2
Observable lists

NOTE!!! Before dismissing this chapter..., please read this information which explains why I had to reinvent some things in .Net. Understanding .Net IBindingList bug and its deficiencies is on the MUST list. And so is probably this explanation which provides reasons why one REALLY should make lists observable by default

While chapter 1 focused on simple classes, chapter 2 focuses on basic lists which provide same notification functionality as INotifyPropertyChanged does.

Now... List... everyone knows lists in .Net. By simply doing this:

IList myList = new ArrayList();
myList.Add (obj1);
myList.Add (obj2);
(myList[1] as MyObjectType).WantedProperty = "some new value";
myList.Add (obj3);
obj3.WantedProperty = "again something new";

you get list class with 3 objects inside and we changed property value. And beside addition you can search, enumerate, remove and so on. So what? Everyone knows that, if they wouldn't then data binding is probably not the topic they should be reading at their stage.

Trouble is that this list doesn't provide any notification which could be usable to know when data was added, removed or changed. What to do? Simple...
By changing invocation in first line of previous example to
IList myList = new ObservableArrayList();
you made that list alive. This list also registers all INotifyPropertyChanged objects and notifies about their changes. Ok, but lets focus first on what this line did.
ObservableArrayList is nothing but already predefined and finished version of wrapper class named ObservableList. Here is complete source for ObservableArrayList

public class ObservableArrayList : ObservableList
{
public ObservableArrayList()
: base (new ArrayList ())
{
}
}

Which only shows one thing. You can wrap everything IList based inside of ObservableList and then receive feedback. ObservableList is implementing interface IListEvents which contains following events

public interface IListEvents
{
event ListChangedEvent ListChanged;
event ElementAddedInListObjectEvent ElementAdded;
event ElementChangedInListObjectEvent ElementChanged;
event ElementRemovedFromListObjectEvent ElementRemoved;
event ElementsInListSortedEvent ElementsSorted;
}

which probably poses a question why INotifyPropertyChanged is supported and IBindingList avoided. Well, avoided? No it isn't. It is just not used as primary source for list notification events. And why not? IBindingList has too big design flaw to be usable in bindings like this one. (design flaw description)

But even so wrapper is provided which enables to wrap events from and to IBindingList all across this data binding library. But for now lets forget useless IBindingList and focus on things that matter.

All you ever need is knowing that all lists inside

<< INotifyPropertyChanged, BaseNotifyPropertyChanged and Notificator
Adaptors - basics >>