in code/src/UI/Services/DragAndDropService/DragAndDropService.cs [145:206]
private void OnDrop(object sender, DragEventArgs e)
{
if (ItemUnderDragCursor != null)
{
ItemUnderDragCursor = null;
}
e.Effects = DragDropEffects.None;
if (e.Data.GetDataPresent(typeof(T)))
{
// Get the data dropped object.
if (e.Data.GetData(typeof(T)) is T data)
{
if (_listView.ItemsSource is ObservableCollection<T> itemsSource)
{
int oldIndex = itemsSource.IndexOf(data);
int newIndex = GetIndexUnderDragCursor();
if (newIndex < 0)
{
if (itemsSource.Count == 0)
{
newIndex = 0;
}
else if (oldIndex < 0)
{
newIndex = itemsSource.Count;
}
else
{
return;
}
}
if (oldIndex != newIndex)
{
if (ProcessDrop != null)
{
// Let the wizard process the drop.
DragAndDropEventArgs<T> args = new DragAndDropEventArgs<T>(itemsSource, data, oldIndex, newIndex, e.AllowedEffects);
ProcessDrop(this, args);
e.Effects = args.Effects;
}
else
{
if (oldIndex > -1)
{
itemsSource.Move(oldIndex, newIndex);
}
else
{
itemsSource.Insert(newIndex, data);
}
e.Effects = DragDropEffects.Move;
}
}
}
}
}
}