Reputation: 699
I have an ObservableCollection, this collection has 2 items (model), the model has Value as a property.
there is an event CollectionChanged for the collection, which suppose to fire when an item is changed, so I am expecting to see this event get fire when a model Value sets but I don't how model should be structured to fire that event?
I know that Model can have an event and when a Model is added a handler can be assigned to this event, but I want to know how CollectionChanged works for change of item in the collection?
Upvotes: 1
Views: 2521
Reputation: 1
A hack is to add a new element to the collection and remove it immediately. That will raise the collectionchanged event.
Upvotes: 0
Reputation: 437754
CollectionChanged
will only be raised when a model replaces another in your collection. Property changes to a model that is already inside the collection will not raise it.
You will need to handle those with the INotifyPropertyChanged.PropertyChanged
event, which your models must expose.
Upvotes: 3
Reputation: 564841
It won't fire if a property within the element is changed, only if you assign a new "model" item to an index of the collection.
If you want WPF to update when you change a property value within your Model class, you need to make the model instances implement INotifyPropertyChanged
.
Upvotes: 2