private void collectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                addItems(e.NewItems);
                break;

            case NotifyCollectionChangedAction.Remove:
                removeItems(e.OldItems);

                // Explicitly reset scroll position here so that ScrollContainer doesn't retain our
                // scroll position if we quickly add new items after calling a Clear().
                if (Items.Count == 0)
                {
                    ScrollContainer.ScrollToStart();
                }
                break;

            case NotifyCollectionChangedAction.Reset:
                currentlyDraggedItem = null;
                ListContainer.Clear();
                itemMap.Clear();
                break;

            case NotifyCollectionChangedAction.Replace:
                removeItems(e.OldItems);
                addItems(e.NewItems);
                break;
            }
        }
        private void removeItems(IList items)
        {
            foreach (var item in items.Cast <TModel>())
            {
                if (currentlyDraggedItem != null && EqualityComparer <TModel> .Default.Equals(currentlyDraggedItem.Model, item))
                {
                    currentlyDraggedItem = null;
                }

                ListContainer.Remove(itemMap[item]);
                itemMap.Remove(item);
            }

            reSort();
        }
 private void endArrangement(RearrangeableListItem <TModel> item, DragEndEvent e) => currentlyDraggedItem = null;
 private void arrange(RearrangeableListItem <TModel> item, DragEvent e) => screenSpaceDragPosition = e.ScreenSpaceMousePosition;
 private void startArrangement(RearrangeableListItem <TModel> item, DragStartEvent e)
 {
     currentlyDraggedItem    = item;
     screenSpaceDragPosition = e.ScreenSpaceMousePosition;
 }