拖放到桌面/资源管理器
按照我的场景。
我有一个应用程序,它将文件结构(文件夹、文件)从数据库加载到 WPF ListView 中。现在我想从此 ListView 中获取一个文件,将其拖到我的桌面(或某个打开的资源管理器窗口)上并将其放在那里。基本的拖放,没什么花哨的。这听起来像是 Windows 应用程序的“标准”功能 - 但谷歌不会提供帮助。
那么我怎样才能实现这一目标呢?互操作?
谢谢
编辑:感谢您的解决方案,我仍然需要进行一些谷歌搜索。 这是我的完整解决方案。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只要您向其传递适当的 DataObject,
DragDrop.DoDragDrop
就可以做到这一点。首先将文件复制到某处。如果没有更好的地方,您可以使用 System.IO.Path.GetTempPath() 。
接下来创建一个包含文件完整路径的字符串数组,并执行以下操作:
实际上可以在不预先复制文件的情况下执行此操作,但这会涉及一些复杂的 IDataObject 交互,因此除非您的文件可能非常大并且“文件系统中尚未存在我会首先尝试此方法。
DragDrop.DoDragDrop
can do this as long as you pass it an appropriateDataObject
.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:
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.