我在應用程序中首先使用EntityFramework數據庫。我想以某種方式被通知在我的ViewModel中對EntityCollection
的更改。它不直接支持INotifyCollectionChanged
(爲什麼?),我還沒有成功找到另一種解決方案。EntityFramework EntityCollection觀察CollectionChanged
這裏是我的最新嘗試,因爲ListChanged
事件似乎並沒有引起人們的關注不工作:
public class EntityCollectionObserver<T> : ObservableCollection<T>, INotifyCollectionChanged where T : class
{
public event NotifyCollectionChangedEventHandler CollectionChanged;
public EntityCollectionObserver(EntityCollection<T> entityCollection)
: base(entityCollection)
{
IBindingList l = ((IBindingList)((IListSource)entityCollection).GetList());
l.ListChanged += new ListChangedEventHandler(OnInnerListChanged);
}
private void OnInnerListChanged(object sender, ListChangedEventArgs e)
{
if (CollectionChanged != null)
CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}
}
有沒有人有我怎麼可能會觀察到變化的EntityCollection
任何想法?
丹
另請參閱http://stackoverflow.com/questions/6264979/changing-association-property-entitycollection-dont-rise-propertychanged – OneWorld 2013-01-14 10:20:52