I'm trying to do custom handling for multiple items in a grouped list box by implementing an IDropHandler. The default behavior without the drop handler works fine all around for single and multi-item drops. However, using IDropHandler fails when calling DragDrop.DefaultDropHandler.Drop() when multiple items are selected and dragged across groups.
Here's my implementation:
This code works for:
- Single Items both within group and across groups
- Multiple Items within the same group
It fails for:
- Multiple items across groups
Here's what this implementation looks like at the failure point:

The error is:

Here's my code:
public class SessionRequestListModel : IDropTarget
{
...
public void DragOver(IDropInfo dropInfo)
{
if (dropInfo.KeyStates.HasFlag( DragDropKeyStates.ControlKey))
dropInfo.Effects = DragDropEffects.Copy;
else
dropInfo.Effects = DragDropEffects.Move;
dropInfo.DropTargetAdorner = DropTargetAdorners.Insert;
}
public void Drop(IDropInfo dropInfo)
{
var item = dropInfo.TargetItem as HttpRequestData;
if (item == null) return;
var sourceItems = dropInfo.Data as List<object>;
if (sourceItems == null)
{
var sourceItem = dropInfo.Data as HttpRequestData;
if (sourceItem == null) return;
sourceItems = new List<object>();
sourceItems.Add(sourceItem);
}
var resultItems = new List<object>();
foreach (HttpRequestData source in sourceItems)
{
HttpRequestData copied = source;
if (dropInfo.Effects == DragDropEffects.Copy)
{
copied = HttpRequestData.Copy(source);
if (!string.IsNullOrEmpty(copied.Name))
copied.Name += " (copy)";
else
copied.Url += " (copy)";
}
if (copied.Group != item.Group)
{
copied.Group = item.Group;
}
resultItems.Add(copied);
}
dropInfo.Data = resultItems;
// TODO: this blows up with multiple items across groups
// but works for single items or multiple items within same group
GongSolutions.Wpf.DragDrop.DragDrop.DefaultDropHandler.Drop(dropInfo);
GroupRefresh();
}
}
Basically what the code is doing is creating a new Data item with a List of drop items which may have updated group data which is a property on the item model. The group is explicitly updated in GroupRefresh(), but the code never gets there for the multi-drop operation. It does work however for a single item which is strange.
I'm creating new data items in order to properly support the Copy operation which needs to create new (not the same reference) items which makes this code more verbose than it otherwise would be. I suspect it has something to do with the new collection that's causing the problems, but still odd that it works with a single item even though that is also in the collection.
I'm trying to do custom handling for multiple items in a grouped list box by implementing an
IDropHandler. The default behavior without the drop handler works fine all around for single and multi-item drops. However, usingIDropHandlerfails when callingDragDrop.DefaultDropHandler.Drop()when multiple items are selected and dragged across groups.Here's my implementation:
This code works for:
It fails for:
Here's what this implementation looks like at the failure point:
The error is:
Here's my code:
Basically what the code is doing is creating a new Data item with a List of drop items which may have updated group data which is a property on the item model. The group is explicitly updated in GroupRefresh(), but the code never gets there for the multi-drop operation. It does work however for a single item which is strange.
I'm creating new data items in order to properly support the Copy operation which needs to create new (not the same reference) items which makes this code more verbose than it otherwise would be. I suspect it has something to do with the new collection that's causing the problems, but still odd that it works with a single item even though that is also in the collection.