void Annotations_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: foreach (var item in e.NewItems) { var viewModel = new AnnotationViewModel(this, item as AnnotationModel); _annotations.Add(viewModel); } break; case NotifyCollectionChangedAction.Reset: _annotations.Clear(); break; case NotifyCollectionChangedAction.Remove: foreach (var item in e.OldItems) { _annotations.Remove(_annotations.First(x => x.AnnotationModel == item)); } break; } }
private void Model_AnnotationAdded(AnnotationModel annotation) { var viewModel = new AnnotationViewModel(this, annotation); _annotations.Add(viewModel); }