question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IDropTarget.DragOver fires as expected, but Drop never fires

See original GitHub issue

Two 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:closed
  • Created 7 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
WillSullivancommented, Jun 13, 2016

@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.

0reactions
RedX2501commented, Oct 5, 2021

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 triggers Drop when I release the mouse over the element. Changing Link to Move immediately works.

It does not matter what I set dropInfo.NotHandled to.

What magic is needed for Link to work?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't get drag and drop events to fire
The drag and drop functionality works on the interface, but the events wont fire. I need the events to fire so I can...
Read more >
JavaScript: Solution: drop event not firing - YouTube
A lot of developers bump into this situation. Your dragstart event handler fires but not the handler for the drop event.
Read more >
The Drag and Drop Component Suite for Delphi - MelanderBlog
PasteFromClipboard no longer clears the data after the OnDrop event has fired. Fixed bug in TClipboardFormat.GetData that caused drop targets to reject data ......
Read more >
Drag and Drop in WPF
An article showing how to add drag and drop to a WPF application using the GongSolutions.Wpf.DragDrop library.
Read more >
[VB6] Register any control as a drop target that shows the ...
I fired up XP with a VM, and the drag image and cursor shown in the Picturebox is 100% identical to the one...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found