c# - How do I update a listview item that is bound to a collection in WPF? -
In WPF, I have a ListView bound for code-behind a ObservableCollection By updating the item adds and removes items from the list.
I have an 'edit' button that opens a dialog 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 am assuming this because I am not actually adding / removing objects from the collection, but rather amending one of the items.
How do I tell the list view that it needs to synchronize the binding source?
You need to apply INotifyPropertyChanged to the item class, such as:
Class ItemClass: INotifyPropertyChanged {public int BoundValue {get {return m_BoundValue; } Set {if (m_BoundValue! = Value) {m_BoundValue = value; OnPropertyChanged ("BoundValue")}}} Zero OnPropertyChanged (string propertyName) {If (PropertyChanged! = Null) {PropertyChanged (New, PropertyChangedEventArgs (propertyName)); }} Int m_BoundValue; }
Comments
Post a Comment