拖放到桌面/资源管理器 [英] Drag and drop to Desktop / Explorer

查看:141
本文介绍了拖放到桌面/资源管理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个将数据库中的Filestructure(文件夹,文件)加载到WPF ListView中的应用程序。现在我想从这个ListView中抓取一个文件,将其拖放到我的桌面(或一些开放的资源管理器窗口)上,然后将其放在那里。基本的拖放,没什么好想的。这听起来像一个Windows应用程序的标准功能,但谷歌不会帮助。



那么我该如何实现呢? Interops?



感谢



修改:感谢您的解决方案,做一些谷歌搜索这是我的完整解决方案

解决方案

DragDrop.DoDragDrop 只要你传递一个适当的 DataObject



首先将文件复制到某处。你可以使用 System.IO.Path.GetTempPath(),如果你没有任何地方更好。



下一页创建一个包含文件完整路径的字符串数组,并执行以下操作:

  string [] paths = ...; 
DragDrop.DoDragDrop(this,new DataObject(DataFormats.FileDrop,paths),
DragDropEffects.Copy);

实际上可以在没有预复制文件的情况下执行此操作,但会导致某些复杂的IDataObject交互,所以除非你的文件可能非常大,并且还没有在文件系统中,我会先尝试这种方法。


Following my scenario.

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?

Thanks

Edit: Thanks for the solution, I still had to do some googling. Here's my complete solution.

解决方案

DragDrop.DoDragDrop can do this as long as you pass it an appropriate DataObject.

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); 

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆