WPF:将虚拟文件拖放到 Windows 资源管理器中

WPF: Drag and drop virtual files into Windows explorer(WPF:将虚拟文件拖放到 Windows 资源管理器中)
本文介绍了WPF:将虚拟文件拖放到 Windows 资源管理器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在开发一个类似于 dropbox 的应用程序,并在 WPF 列表视图中显示远程文件.我想将这些元素拖放到 Windows 资源管理器中.我见过这样的代码:

I'm developing an application similar to dropbox and i show the remote files on a WPF listview. I want to drag those elements and drop it into windows explorer. I've seen code like this:

var dataObject = new DataObject(DataFormats.FileDrop, files.ToArray());
dataObject.SetData(DataFormats.StringFormat, dataObject);
DoDragDrop(dataObject, DragDropEffects.Copy);

但正如您可能认为的那样,这些文件还没有在本地系统中,在复制它们之前,我需要连接到服务器,下载并解压缩文件.就像 ftp 客户端一样.

But as you may think, those file are not at the local system yet, before copiying them I need to connect to server, donwload and unzip the files. Like a ftp client does.

我不知道怎么做,但我想知道是否有任何drop"事件或类似的我可以处理.

I dont how to do it but i was wondering if there is any "drop" event or similiar that i can handle.

谢谢!

推荐答案

这段代码:

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"));
            virtualFileDataObject.SetData(
                (short)(DataFormats.GetDataFormat(DataFormats.Text).Id),
                Encoding.Default.GetBytes("[The RSS feed for Delay's Blog]"));

            DoDragDropOrClipboardSetDataObject(e.ChangedButton, TextUrl, virtualFileDataObject, DragDropEffects.Copy);

使用类 linked 应该可以工作..非常好的和简单的解决方案.

Using the class linked should work. . Very nice and easy solution.

这篇关于WPF:将虚拟文件拖放到 Windows 资源管理器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Force JsonConvert.SerializeXmlNode to serialize node value as an Integer or a Boolean(强制 JsonConvert.SerializeXmlNode 将节点值序列化为整数或布尔值)
Using JSON to Serialize/Deserialize TimeSpan(使用 JSON 序列化/反序列化 TimeSpan)
Could not determine JSON object type for type quot;Classquot;(无法确定类型“Class的 JSON 对象类型.)
How to deserialize a JSONP response (preferably with JsonTextReader and not a string)?(如何反序列化 JSONP 响应(最好使用 JsonTextReader 而不是字符串)?)
how to de-serialize JSON data in which Timestamp it-self contains fields?(如何反序列化时间戳本身包含字段的JSON数据?)
JSON.Net custom contract serialization and Collections(JSON.Net 自定义合约序列化和集合)