Chapter147:ObservableCollection

No Comments

Section147.1:InitializeObservableCollection<T>

ObservableCollectionisacollectionoftypeTlikeList<T>whichmeansthatitholdsobjectsoftypeT. From documentation we read that :

ObservableCollectionrepresentsadynamicdatacollectionthatprovidesnotificationswhenitemsget added, removed, or when the entire list is refreshed.

The key difference from other collections is that ObservableCollectionimplements the interfaces INotifyCollectionChangedandINotifyPropertyChangedandimmediatelyraisenotificationeventwhenanew objectisaddedorremovedandwhencollectioniscleared.

This is especially useful for conneting the UI and backend of an application without having to write extra code because when an object is added to or removed from an observable collection, the UI is automatically updated.

Thefirststepinordertouseitistoinclude

usingSystem.Collections.ObjectModel

Youcaneithercreateanemptyinstanceofacollectionforexampleoftypestring

ObservableCollection<string>collection=newObservableCollection<string>();

oraninstancethatisfilledwithdata

ObservableCollection<string>collection=newObservableCollection<string>()

{

“First_String”,”Second_String”

};

RememberasinallIListcollection,indexstartsfrom0(IList.ItemProperty).

About us and this blog

We are a digital marketing company with a focus on helping our customers achieve great results across several key areas.

Request a free quote

We offer professional SEO services that help websites increase their organic search score drastically in order to compete for the highest rankings even when it comes to highly competitive keywords.

Subscribe to our newsletter!

More from our blog

See all posts
No Comments

Recent Posts

Leave a Comment