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..
Here is a drop-in class that sub-classes ObservableCollection and actually raises a Reset action when a property on a list item changes. It enforces all items to implement
INotifyPropertyChanged
.The benefit here is that you can data bind to this class and all of your bindings will update with changes to your item properties.
Instead of an ObservableCollection or TrulyObservableCollection, consider using a BindingList and calling the ResetBindings method.
For example:
Given an event, such as a click your code would look like this:
My model looked like this:
I know that I'm too late for this party, but maybe - it will help to someone..
Here you can find my implementation of ObservableCollectionEx. It has some features:
Of course, any comments are appreciated ;)
Just adding my 2 cents on this topic. Felt the TrulyObservableCollection required the two other constructors as found with ObservableCollection:
Simple solution for standard observablecollection that I've used:
DO NOT ADD to your property OR CHANGE it's inner items DIRECTLY, instead, create some temp collection like this
and add items or make changes to tmpList,
then pass it to your actual property by assignment.
this will change whole property which causes notice the INotifyPropertyChanged as you need.
Added to TruelyObservableCollection event "ItemPropertyChanged":