You're confusing the INotifyCollectionChanged
interface with the INotifyPropertyChanged
interface. It sounds like you want to know when any property of any item in the collection changes. In order to make that happen, you will need to implement the INotifyPropertyChanged
interface in your data type class and attach a handler to the INotifyPropertyChanged.PropertyChanged
event:
item.PropertyChanged += Item_PropertyChanged;
private void Item_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
// The 'e.PropertyName' property changed
}
You can improve this further by extending the ObservableCollection<YourDataType>
class and adding this code into that class:
public new void Add(T item)
{
item.PropertyChanged += Item_PropertyChanged;
base.Add(item);
}
...
public new bool Remove(T item)
{
if (item == null) return false;
item.PropertyChanged -= Item_PropertyChanged;
return base.Remove(item);
}
There are also other methods that you should override in this way, but once you have, you can just let this class do all of the work for you... even better if you put it into some kind of generic base class. If you make that class also implement the INotifyPropertyChanged
interface, then you can also 'forward' all property changes for convenience:
private void Item_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
NotifyPropertyChanged(e.PropertyName);
}