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.
我得到了一个应用程序,该应用程序将数据库中的文件结构(文件夹、文件)加载到WPF列表视图中。现在,我想从这个列表视图中抓取一个文件,将它拖到我的桌面(或某个打开的资源管理器窗口)并将它放在那里。基本的拖放,没什么特别的。这听起来像是windows应用程序的“标准”函数——但是谷歌没有帮助。
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.
编辑:谢谢你的解决方案,我还得上网搜索一下。这是我的完整的解决方案。
1 个解决方案
#1
27
DragDrop.DoDragDrop
can do this as long as you pass it an appropriate DataObject
.
DragDrop。只要传递一个合适的DataObject, DoDragDrop就可以这样做。
First copy the files somewhere. You can use System.IO.Path.GetTempPath()
if you don't have anywhere better.
首先把文件复制到某个地方。如果你没有更好的地方,你可以使用system . io.p。gettemppath()。
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.
实际上,不需要预先复制文件就可以做到这一点,但是这会涉及到一些复杂的IDataObject交互,所以除非您的文件可能非常大,而且还没有在文件系统中,否则我将首先尝试这个方法。
#1
27
DragDrop.DoDragDrop
can do this as long as you pass it an appropriate DataObject
.
DragDrop。只要传递一个合适的DataObject, DoDragDrop就可以这样做。
First copy the files somewhere. You can use System.IO.Path.GetTempPath()
if you don't have anywhere better.
首先把文件复制到某个地方。如果你没有更好的地方,你可以使用system . io.p。gettemppath()。
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.
实际上,不需要预先复制文件就可以做到这一点,但是这会涉及到一些复杂的IDataObject交互,所以除非您的文件可能非常大,而且还没有在文件系统中,否则我将首先尝试这个方法。