0
votes

I know the difference between a List and ObservableCollection from ObservableCollection<> vs. List<> but sources like Microsoft Xamarin.Forms docs say that

Because ItemsSource has been sent to an array, the content will not update as the underlying list or array changes. If you want the ListView to automatically update as items are added, removed and changed in the underlying list, you'll need to use an ObservableCollection. ObservableCollection is defined in System.Collections.ObjectModel and is just like List, except that it can notify ListView of any changes:

So what exactly would be different if I implemented a List as the ItemSource for my ListView in Xamarin.Forms in contrast to an ObservableCollection if data binding is done. Also, my List or OC consists of multiple levels of Lists or OCs of different objects.

Ex:

List<Data> = new List<Data>();

class Data{
  public List<SomeOtherData> {get; set;}
}
1
Changes in code to the list will not be automatically shown in your ListView. ObservableCollection implements some INotifyXXX interface that will trigger a refresh by the Listview to show those changes if needed. - Ralf
@Ralf that depends, is binding involved? If not, it's of no use. - zaggler
The question itself needs more clarity IMHO. You're asking about the difference among the two in terms of how they are used/referenced as an object to an ItemSource property. But it depends if binding is involved etc... Please clarify this as you have pointed out already, that you know the difference between the two. - zaggler

1 Answers

2
votes

With a regular List, when you update it (let us say by adding or removing something) your UI won't show that change even though in memory it is different. However, with an ObseravableCollection it will(exactly as the explanation states above).

That would be the biggest change really. If you implement it as a List you would have to manually update the list's ItemSource to honor whatever changes you have made