IDropTarget.DragOver fires as expected, but Drop never fires
See original GitHub issueTwo list boxes bound to two different collections. One is the source, the other the target. The target has AllowDrop="True"
(I’m cargo culting at this point) and a DragDrop.DropHandler bound to a property on the view model.
(quick aside–the view model in this case is a wrapper around a model that allows me to attach properties used in the UI, such as a drop handler to a model. Also, tons of fat trimmed from example code).
<ListBox AllowDrop="True" ItemsSource="{Binding HERPS}" dd:DragDrop.IsDropTarget="True" dd:DragDrop.DropHandler="{Binding DropHandler}" />
<ListBox ItemsSource="{Binding Configuration.DERPS}" dd:DragDrop.IsDragSource="True" />
The drop handler is simple
public sealed class DropHandler : IDropTarget
{
public const string DropHandlerPropertyName = "DropHandlerCommand";
private readonly BaseModelViewModel _target;
public DropHandler(BaseModelViewModel target)
{
_target = target;
}
public void DragOver(IDropInfo dropInfo)
{
dropInfo.DropTargetAdorner = DropTargetAdorners.Insert;
dropInfo.Effects = DragDropEffects.Link;
}
public void Drop(IDropInfo dropInfo)
{
var handler = _target.GetPropertyValue(DropHandlerPropertyName) as ICommand;
if (handler == null) return;
handler.Execute(dropInfo);
}
}
For each wrapped something I grab their drop handler (an ICommand implementation) on drop and pass in the drop info. Nothing crazy here.
Now, when I drag an item from DERPS over into HERPS, IDropTarget.DragOver(IDropInfo dropInfo)
does get called. I can see that dropInfo.Data
contains the correct data, and that dropInfo.TargetCollection
is the correct collection. Everything else looks correct as well, except for TargetItem and VisualTargetItem being null (not sure if that’s bad or not).
I can also see a visual indication that an insert is going to happen within the list box. There is a line that indicates where the item will be inserted. So everything appears nice and happy, but…
The mouse cursor never changes from the “no drop” icon when hovering over the drop target. And when I release the mouse, IDropTarget.Drop(IDropInfo dropInfo)
does not fire.
Any guesses why? I didn’t see anything in the samples that stood out as “DO THIS OR IT DONT WORK”. Any hints as to what I can do to debug this further? I’m a bit at a loss, and am about at the point where I have to strip everything out and re-add it bit by bit to see what breaks the drag/drop magic 😦
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (8 by maintainers)
@punker76 I set
dropInfo.NotHandled
to True in the DragOver method and now it works. Not sure if that is not supposed to be required in order for it to work.I do realize that this is a very old topic but it fits my problem exactly.
I’m using 2.4.3
If I set in DragOver the
dropInfo.Effects = DragDropEffects.Link
it shows the drop not allowed symbol and never triggersDrop
when I release the mouse over the element. ChangingLink
toMove
immediately works.It does not matter what I set
dropInfo.NotHandled
to.What magic is needed for
Link
to work?