I'd be interested to know how people go about solving this rather common problem.
In an MVVM type application, I have an ObservableCollection containing a set of things which I want displayed in the GUI. I've used ObservableCollection so that it can handle things being added/removed/replaced etc. so I don't have to do the collection change notification myself. To keep it simple, let's just use strings as the things in the collection.
To initially populate this collection, and to
regularly update it I have a data access method which gives me a generic list of string. This is called at regular intervals.
So, to instantiate the ObservableCollection I can just do this:
List<string> itemsFromDb = GetListOfStringsFromDatabase();
MyObservableCollection = new ObservableCollection(itemsFromDb);
At regular poll intervals, I call
GetListOfStringsFromDatabase()
again, and now want to merge this into the existing records in the OC.
The OC is stateful, the List is not. I can compare the two, remove things from the OC not in the list, and insert things that are missing but I don't really feel I should need to do this.
A simple way to keep an ObservableCollection up to date by repeatedly providing a 'target' list - any thoughts?