Wpf listview observablecollection not updating

09-Dec-2014 22:32

It wasn’t the collection that changed, it was the property that points to the collection.

The binding is not to the property of the parent object, but to that specific instance of the collection itself.

A common mistake is to modify the parent object’s property and replace one Observable Collection with another.

Observable Collection is one of the most useful classes in WPF and Silverlight data binding.

Whenever you modify the collection, the view is notified. These are some of the mistakes I see from beginners and experts alike.

When a view binds to an Observable Collection, it subscribes to events from that instance.

It expects to be notified when items are added, removed, or replaced within that instance of the collection.

Just about every person who uses Observable Collections makes this mistake at least once.

Even Scott Hanselman made this mistake on stage at Mix ‘09 (skip to ).

Not only is this inefficient, but it also scrolls back to the top of the list rather than preserving the user’s context.

This fix completely obviates the need for an Observable Collection in the first place.

This causes the view to unbind from the old one and rebind to the new one.

In this situation, the view can’t adjust to just the items that were added or removed; it has to rebind the entire list box.