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..
If i know ObservableCollection make event only when we add/delete or move items in our collection. When we simly update some properties in collection items collection don`t signalize about it and UI will not be updated.
You can simly implement INotifyPropertyChange in your Model class. And than when we update some propery in collection item it automatically will update UI.
and than
In my case i used ListView to Bind for this collection and in ItemTemplate set Binding to Model property and it work good.
Here is some snippet
Windows XAML :
Model code example:
And ViewModel implementation:
Here's an extension method for the above solution...
I used Jack Kenyons answer to implement my own OC, but I'd like to point out one change i had to make to make it work. Instead of:
I used this:
It seems that the "e.NewItems" produces null if action is .Remove.
I try this solution, but only works for me like a RaisePropertyChange("SourceGroupeGridView") when collection changed, that fired for each item add or changed.
The problem is in:
NotifyCollectionChangedAction.Reset this action make a complete rebind of all items in groupedgrid, is equivalent at RaisePropertyChanged. When you use it all groups of gridview refreshed.
IF you, only want to refresh in UI the group of the new item, you don't use Reset action, you will need simulate a Add action in itemproperty with something like this:
Sorry by my english, and thanks for the base code :), I hope this helps someone ^_^
Enjoi!!