How to update the list item associated with a collection in WPF?

In WPF, I have a ListView associated with an ObservableCollection in code. I have working code that adds and removes items from a list, updating the collection.

I have a Change button that opens a dialog box and allows the user to edit the values ​​for the selected ListView item. However, when I change the item, the list view is not updated. I suppose this is because I am not actually adding / removing elements from the collection, but simply changing one of my elements.

How do I show the list view that it needs to synchronize the binding source?

+4
source share
2 answers

You need to implement INotifyPropertyChanged in the element class, for example:

class ItemClass : INotifyPropertyChanged { public int BoundValue { get { return m_BoundValue; } set { if (m_BoundValue != value) { m_BoundValue = value; OnPropertyChanged("BoundValue") } } } void OnPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } int m_BoundValue; } 
+8
source

Is the binding mode set to TwoWay? If not, try to do this.

+1
source

All Articles