拖放到桌面/浏览器 [英] Drag and drop to Desktop / Explorer
问题描述
随着我的方案。
我得到了一个应用程序,它加载一个Filestructure(文件夹,文件),从数据库到一个WPF的ListView。现在,我想从这个ListView中获取文件,将它拖到了我的台式机(或打开资源管理器窗口),并把它在那里。基本拖放,没有什么花哨。这听起来像一个标准功能的Windows应用程序 - 但谷歌不会帮助
I got an Application which loads a Filestructure (Folders, Files) from a Database into a WPF ListView. Now I'd like to grab a file from this ListView, drag it over my Desktop (or some open explorer window) and drop it there. Basic Drag and Drop, nothing fancy. This sounds like a "standard" function for a windows application - but google won't help.
所以,我怎么能做到这一点?互操作性展示?
So how can I achieve this? Interops?
感谢
修改:谢谢你的解决方案,我还是不得不做一些谷歌上搜索。 这是我的完整的解决方案。
Edit: Thanks for the solution, I still had to do some googling. Here's my complete solution.
推荐答案
DragDrop.DoDragDrop
能做到这一点,只要你把它传递一个合适的数据对象
。
DragDrop.DoDragDrop
can do this as long as you pass it an appropriate DataObject
.
首先某处复制文件。您可以使用 System.IO.Path.GetTempPath()
如果你没有地方好。
First copy the files somewhere. You can use System.IO.Path.GetTempPath()
if you don't have anywhere better.
接下来创建一个字符串数组,包含的完整路径的文件,并执行以下操作:
Next create a string array containing the full paths to the files and do the following:
string[] paths = ...;
DragDrop.DoDragDrop(this, new DataObject(DataFormats.FileDrop, paths),
DragDropEffects.Copy);
这其实是可以做到这一点没有pre-复制文件但进入一些复杂的IDataObject的互动,所以,除非您的文件可能非常大,是不是已经在文件系统中我先试试这个方法
It is actually possible to do this without pre-copying the files but that gets into some complicated IDataObject interactions, so unless your files are potentially very large and aren't already in the filesystem I would try this method first.
这篇关于拖放到桌面/浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!