Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Snippet related to NotifyCollectionChangedAction.Move taken from the code that is used to keep two collections in sync.
case NotifyCollectionChangedAction.Move:
{
// Loosely based on http://stackoverflow.com/a/450250/86845
int newIndex = e.NewStartingIndex;
int oldIndex = e.OldStartingIndex;
int itemsCount = e.OldItems.Count;
// get a copy of the items that are to be moved
List<T> items = otherList.Skip(oldIndex).Take(itemsCount).ToList();
// remove from old indexes
otherList.RemoveRange(oldIndex, itemsCount);
// adjust for index shifts caused by removal
if (newIndex > oldIndex)
{
newIndex -= itemsCount;
}
// insert at the new index
otherList.InsertRange(newIndex, items);
}
break;
@joaoportela

This comment has been minimized.

Copy link
Owner Author

@joaoportela joaoportela commented Aug 22, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment