简体   繁体   English

WPF拖放DragDropEffects更改离开WPF窗口时的效果

[英]WPF Drag and Drop DragDropEffects changing when moving off of WPF Window

I have a WPF application where I'm dragging an file object around. 我有一个WPF应用程序,在其中拖动文件对象。 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. 拖放操作可以正常工作,但是DragDropEffect仅在应用程序窗口内部正确显示。 When the cursor moves outside of the App window I get the 'verboten' icon - most of the time. 当光标移到“应用程序”窗口之外时,大多数时候会显示“ verboten”图标。 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. 如前所述,shell的代码和处理方式正常工作-文件被复制,仅是拖动图标才是问题。

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? 那么如何在WPF外部可靠地控制拖动图标?

https://docs.microsoft.com/en-us/dotnet/api/system.windows.dragdrop.givefeedback https://docs.microsoft.com/zh-cn/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. 您应该(根据Microsoft的文档)缓存游标等,因为在拖动时会一遍又一遍地调用它,并且您不希望在发生拖动时加载LoadResource。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM