Я сначала использую базу данных EntityFramework в приложении. Я хотел бы каким-то образом получать уведомления об изменениях в EntityCollection
в моей модели ViewModel. t напрямую поддерживает INotifyCollectionChanged
(почему?), и мне не удалось найти другое решение.
Вот моя последняя попытка, который не работает, потому что событие 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
?
Дэн