Mor*_*der 8 c# wpf drag-and-drop
我正在开发一个类似于dropbox的应用程序,我在WPF列表视图中显示远程文件.我想拖动这些元素并将其放入Windows资源管理器中.我见过这样的代码:
var dataObject = new DataObject(DataFormats.FileDrop, files.ToArray());
dataObject.SetData(DataFormats.StringFormat, dataObject);
DoDragDrop(dataObject, DragDropEffects.Copy);
Run Code Online (Sandbox Code Playgroud)
但是你可能认为,那些文件还没有在本地系统上,在复制它们之前我需要连接到服务器,下载并解压缩文件.像ftp客户端一样.
我不知道怎么做,但我想知道是否有任何"掉落"事件或类似我能处理.
谢谢!
这个片段:
var virtualFileDataObject = new VirtualFileDataObject(
// BeginInvoke ensures UI operations happen on the right thread
(vfdo) => Dispatcher.BeginInvoke((Action)(() => BusyScreen.Visibility = Visibility.Visible)),
(vfdo) => Dispatcher.BeginInvoke((Action)(() => BusyScreen.Visibility = Visibility.Collapsed)));
// Provide a virtual file (downloaded on demand), its URL, and descriptive text
virtualFileDataObject.SetData(new VirtualFileDataObject.FileDescriptor[]
{
new VirtualFileDataObject.FileDescriptor
{
Name = "DelaysBlog.xml",
StreamContents = stream =>
{
using(var webClient = new WebClient())
{
var data = webClient.DownloadData("http://blogs.msdn.com/delay/rss.xml");
stream.Write(data, 0, data.Length);
}
}
},
});
virtualFileDataObject.SetData(
(short)(DataFormats.GetDataFormat(CFSTR_INETURLA).Id),
Encoding.Default.GetBytes("http://blogs.msdn.com/delay/rss.xml\0"));
virtualFileDataObject.SetData(
(short)(DataFormats.GetDataFormat(DataFormats.Text).Id),
Encoding.Default.GetBytes("[The RSS feed for Delay's Blog]\0"));
DoDragDropOrClipboardSetDataObject(e.ChangedButton, TextUrl, virtualFileDataObject, DragDropEffects.Copy);
Run Code Online (Sandbox Code Playgroud)
使用链接的类应该可以工作。. 非常好的和简单的解决方案。