Does anyone know why this code doesn’t work:
public class CollectionViewModel : ViewModelBase {
public ObservableCollection<EntityViewModel> ContentList
{
get { return _contentList; }
set
{
_contentList = value;
RaisePropertyChanged("ContentList");
//I want to be notified here when something changes..?
//debugger doesn't stop here when IsRowChecked is toggled
}
}
}
public class EntityViewModel : ViewModelBase
{
private bool _isRowChecked;
public bool IsRowChecked
{
get { return _isRowChecked; }
set { _isRowChecked = value; RaisePropertyChanged("IsRowChecked"); }
}
}
ViewModelBase containts everything for RaisePropertyChanged etc. and it’s working for everything else except this problem..
The ContentList’s Set method will not get called when you change a value inside the collection, instead you should be looking out for the CollectionChanged event firing.
Okay, that’s twice today I’ve been bitten by the MSDN documentation being wrong. In the link I gave you it says:
But it actually doesn’t fire when an item is changed. I guess you’ll need a more bruteforce method then:
If you are going to need this a lot you may want to subclass your own
ObservableCollectionthat triggers theCollectionChangedevent when a member triggers itsPropertyChangedevent automatically (like it says it should in the documentation…)