Wpf listview binding observablecollection not updating


25-Aug-2015 12:03

Windows Presentation Foundation (WPF) data binding provides a simple and consistent way for applications to present and interact with data.

Collection Changed event – it does not fire when your data item’s property changes. That is if you have a collection of an Entity “Expense” that has properties “Name” and “Amount” and if you simply change the Amount value in the grid it does not work!

You need to replace the entire “Expense” object for you to see the collection change firing up.

If you are using MVVM you do not want to wire up the event on Data Grid for an updated source.

So if you want to know the change in items of the collection you need to subscribe to the Collection Changed event of the Observable Collection But there is a problem with Observable Collection.

I also set Is Synchronized With Current Item property to true.

This property ensures that the selected item always correspond to the Current Item property in Item Collection.

which implements the INotify Property Changed interface, updating the source of items for a List Box or other control can be done almost “automatically” with Data Binding.

In Code behind, i created one class called People and created one Observable Collection of People class.I added few data to that collection and set window’s Data Context property to Obserable Collection. Your View Model will fire the property changed when the collection itself changes – that is if you replace the property itself. You will very much think that as long as you bind the collection to the View Model’s property and the mode is set to Two Way – the source is updated automatically when items are edited in the Data Grid.

For example, I have two listbox and both are bound with same itemsource property.

Now if I change selected item in any of the listbox it will automatically change selection in other listbox if the Is Synchronized With Current Item property is set to true in both Listbox.