I get a list of objects with some properties through a web request. Now I want to display those objects with properties in a list (I use WPF ListBox with DataTemplate) and refresh it every 5 seconds. I know two approaches to that:
- Every 5 seconds clear the list and populate it with newly received data. This approach results in some nasty things like losing current selection and tooltip flickering
- Try to find matching elements and update their properties; then add new elements to collection and remove deleted. This approach keeps references to existing objects just updating their contents and results in less buggy GUI. But this one is considerably harder to implement
What approach should I use? Maybe there are existing (simple) solutions to second one?
Update
Looks like I need to clarify my question. I indeed use ObservableCollection<T>
with two way binding. The problem is, when I want to update I make a web request and get another collection with different instances of objects. What I'm asking is how to apply changes from new collection to old one.