Example #1
0
        private void OnAnnotationsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                foreach (Annotation annot in e.NewItems)
                {
                    AddAnnotation(annot);
                }
            }
            else if (e.Action == NotifyCollectionChangedAction.Remove)
            {
                var items = new List <Annotation>();
                foreach (Annotation annot in e.OldItems)
                {
                    items.Add(annot);
                }
                RemoveAnnotations(items.ToArray());
                foreach (var item in items)
                {
                    _annotationDictionaries.Remove(item.Id);
                }
            }
            else if (e.Action == NotifyCollectionChangedAction.Reset)
            {
                map.RemoveAnnotations();
                _annotationDictionaries.Clear();
            }
            else if (e.Action == NotifyCollectionChangedAction.Replace)
            {
                var itemsToRemove = new List <Annotation>();
                foreach (Annotation annot in e.OldItems)
                {
                    itemsToRemove.Add(annot);
                }
                RemoveAnnotations(itemsToRemove.ToArray());


                var itemsToAdd = new List <Annotation>();
                foreach (Annotation annot in e.NewItems)
                {
                    itemsToRemove.Add(annot);
                }
                AddAnnotations(itemsToAdd.ToArray());
            }
        }