1
votes

I have a WPF application where I'm dragging an file object around. It can be dropped either into several windows inside of the application, or externally into Explorer and onto the desktop and a few other places.

The drag and drop operation works fine, but the DragDropEffect only shows properly inside of the application Window. When the cursor moves outside of the App window I get the 'verboten' icon - most of the time. Depending on how the cursor leaves the app most of the time I get the slashed out circle. But sometimes it correctly continues dragging with the copy icon.

var files = new[] {editor.MarkdownDocument.Filename} ;
var dragData = new DataObject(DataFormats.FileDrop,files);

DragDrop.DoDragDrop(tab, dragData, DragDropEffects.Copy);

As mentioned the code and the handling by the shell works properly - the file is copied, it's only the drag icon that's the problem.

I can control the drag icon inside of the application, no problem on the window, but I have no control what happens outside of it.

So how do I control the drag icon reliably external to WPF?

1
Could it be related to UAC? Two apps on different UAC level can't talk. So it you run you WPF app as admin, and your explorer is restricted (the default), D&D won't work.Simon Mourier
Not in this case - everything is running in user mode. I have noticed though that Windows is doing strange stuff with drag and drop everywhere in a few cases not properly showing the drag icon. Not quite the same. Rebooted and now see more differerent weird stuff. Wondering now if there might be an issue with Windows itself that's causing all this.Rick Strahl
Maybe some 3rd party software is playing weird with the Shell? I'd check what .dlls are loaded into explorer.exe (with sysinternals' procexp or autoruns tools for example)Simon Mourier

1 Answers

0
votes

https://docs.microsoft.com/en-us/dotnet/api/system.windows.dragdrop.givefeedback

DragDrop.GiveFeedback += SetTheCursorHere;

You should (per Microsoft's documentation) cache the cursor, etc. because it's called over and over again while dragging, and you don't want to LoadResource as the drag occurs.