public void Drop(IDropInfo dropInfo) { if (dropInfo.Data is ImageListBoxItem) { // move images var idx1 = ImageListItems.IndexOf(dropInfo.Data as ImageListBoxItem); var idx2 = dropInfo.InsertIndex; if (idx1 < 0 || idx2 < 0) { return; } // did the order change? if (idx1 == idx2) { return; } // move image want the final position of the moved image if (idx1 < idx2) { idx2--; } // put item from idx1 into the position it was dragged to models.Images.MoveImage(idx1, idx2); } else if (dropInfo.Data is DataObject) { var obj = dropInfo.Data as System.Windows.DataObject; var items = obj.GetFileDropList(); if (items == null) { return; } int desiredPosition = dropInfo.InsertIndex; foreach (var file in items) { if (windowViewModel.ImportImage(file)) { // put inserted image into correct position models.Images.MoveImage(models.Images.NumImages - 1, desiredPosition++); } } } }
public async void Drop(IDropInfo dropInfo) { if (dropInfo.Data is ImageItemViewModel vm) { // move images var idx1 = ImageListItems.IndexOf(vm); var idx2 = dropInfo.InsertIndex; if (idx1 < 0 || idx2 < 0) { return; } // did the order change? if (idx1 == idx2) { return; } // move image want the final position of the moved image if (idx1 < idx2) { idx2--; } // put item from idx1 into the position it was dragged to models.Images.MoveImage(idx1, idx2); } else if (dropInfo.Data is DataObject obj) { var items = obj.GetFileDropList(); int desiredPosition = dropInfo.InsertIndex; foreach (var file in items) { await import.ImportImageAsync(file); // put inserted image into correct position models.Images.MoveImage(models.Images.NumImages - 1, desiredPosition++); } } }