Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ObservableCollection tutorial? [closed]

Will anyone direct me to some simple, graphical tutorial on how to use ObservableCollection. I went through msdn but I don't seem to understand them. I can't seem to find better ones on google either. I'm looking for simple example with full explanation on all steps.

like image 222
KMC Avatar asked Dec 15 '10 13:12

KMC


People also ask

Why do we use ObservableCollection in C#?

An ObservableCollection is a dynamic collection of objects of a given type. Objects can be added, removed or be updated with an automatic notification of actions. When an object is added to or removed from an observable collection, the UI is automatically updated.

What is the difference between ObservableCollection and list?

The true difference is rather straightforward:ObservableCollection implements INotifyCollectionChanged which provides notification when the collection is changed (you guessed ^^) It allows the binding engine to update the UI when the ObservableCollection is updated. However, BindingList implements IBindingList.

How do you use observable collection?

The observable collection works just the same way. If you add or remove something to or from it: someone is notified. And when they are notified, well then they call you and you'll get a ear-full. Of course the consequences are customisable via the event handler.


3 Answers

I don't know of any graphical tutorial of ObservableCollection. The ObservableCollection<T> class is a collection type (like List<T>) which means that it holds objects of a given type T. What makes ObservableCollection special is that it "tells" observers when a new object is added or when an object is removed. This is especially useful for UI's implemented using WPF, because esentially, when an object is added to or removed from an observable collection, the UI is automatically updated. This happens because, when binding to an observable collection, WPF automatically adds an event handler to the ObservableCollecion's CollectionChanged event.

like image 156
Klaus Byskov Pedersen Avatar answered Oct 05 '22 05:10

Klaus Byskov Pedersen


If you know how to use a List , use a List and after that just replace the world 'List' with 'ObservableCollection'.

That's all !! isn't it simple ? :)

And now, every time the collection is changed (item been added\ removed\ replaced) Your bounded UI will be notified about it.

like image 35
Erez Avatar answered Oct 05 '22 05:10

Erez


This is a nice introductory article: http://www.codeproject.com/KB/silverlight/SLListVsOCollections.aspx

like image 24
devdigital Avatar answered Oct 05 '22 05:10

devdigital