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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
WARNING:
This code has a bug. see: https://stackoverflow.com/questions/1256793/mvvm-sync-collections/2177659?noredirect=1#comment90651827_2177659