Advertisement
Beginner .NET MAUI, Advanced Data Binding & Collections

What is ObservableCollection and why use it for lists?

Short answer

ObservableCollection implements INotifyCollectionChanged, so adding/removing items automatically updates a bound CollectionView without rebinding. Use it for dynamic lists.

Save .NET MAUI mock interview
Advertisement
AModel answer
ObservableCollection<T> implements INotifyCollectionChanged, so adding/removing items automatically updates a bound CollectionView without rebinding. Use it for dynamic lists. Note that replacing the whole collection still requires a property change notification on the property holding it.
public ObservableCollection<Item> Items { get; } = new();
Items.Add(newItem);   // UI updates automatically
Real-world example
A chat list appends incoming messages to an ObservableCollection and they appear instantly without refreshing the whole view.
Likely follow-ups
  • Does it notify on item property changes? | What if you replace the collection?
Related topics