void ActiveEvents_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: foreach (IEvent ev in e.NewItems) { if (_filter.Apply(ev.Definition)) { _events.Insert(0, new EventViewModel(ev)); } } break; case NotifyCollectionChangedAction.Remove: foreach (IEvent ev in e.OldItems) { foreach (EventViewModel evm in _events) { if (evm.Definition.Id == ev.Definition.Id) { _events.Remove(evm); break; } } } break; case NotifyCollectionChangedAction.Reset: _events.Clear(); break; } }
public EventsSummaryViewModel(IEventsSource es, IEventFilter filter) { _evsource = es; _events = new ObservableCollectionEx <EventViewModel>(_evsource.Events.Where(ev => filter.Apply(ev.Definition)).Select(ev => new EventViewModel(ev))); //_evsource.EventChanged += new EventChanged(_evsource_EventChanged); _evsource.Events.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(ActiveEvents_CollectionChanged); _filter = filter; StateColor = Brushes.Green; System.Timers.Timer _timer = new System.Timers.Timer(1000); _timer.Elapsed += new System.Timers.ElapsedEventHandler(_timer_Elapsed); _timer.Start(); }