Wpf datagrid observablecollection not updating
This interface raises an event whenever the collection is modified by insertion, removal, or replacement.A List does not implement this interface, so anything data bound to it will not be notified when it changes. The two cannot be used together without extra help. When using an Observable Collection, you explicitly call Add, Remove, and other methods to change the collection. Once you use linq on an Observable Collection, it is no longer observable.So it stands to reason that Observable Collection belongs in the view model. Microsoft’s own code generators encourage us to make this mistake.When you add a reference to a WCF service returning a List, the proxy turns that into an Observable Collection.You can data bind a list box directly to a List, if you want.The advantage of Observable Collection over List is that it implements INotify Collection Changed.The handler completes before the Add or Remove method returns.This means that you can’t modify an Observable Collection in a background thread.
This fix completely obviates the need for an Observable Collection in the first place.
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.
Most people who run into this problem realize their mistake quickly.
They wrap the code that modifies the collection in a delegate, and invoke it on the UI thread.