使用WPF和数据绑定将文件拖放到应用程序窗口中 [英] Drag and drop a file into application window using WPF and data binding

查看:312
本文介绍了使用WPF和数据绑定将文件拖放到应用程序窗口中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个文件(例如从桌面或资源管理器)拖放到WPF应用程序的主窗口中。



我也想要没有代码,即我想使用数据绑定。



到目前为止,我测试了gong-wpf-dragdrop似乎不支持拖动目标应用程序。



我可以将一个文件拖放到主窗口并拖放事件触发 - 但数据为空(拖动非空文本文件)。



编辑:gong-wpf-dragdrop工程(小修复后),并且使用代码后也出现问题。



因此,完整的解决方案是使用gong wpf( github )和解决方案

您尝试过 GetFileDropList 方法?您可以从 Drop 事件中的e.Data检索它。



如下:

  string filename = DataObject)e.Data).GetFileDropList()[0]; 


I'd like to be able to drag and drop a file (e.g. from Desktop or Explorer) right into the main window of a WPF application.

I also want no code behind, i.e. I want to use data binding.

So far I tested the "gong-wpf-dragdrop" which doesn't seem to support drag targets outside the application.

I could drop a file to the main window and the drag and drop events fired - but the data was empty (dragged a non-empty text file).

EDIT: gong-wpf-dragdrop works (after a small fix) and the problem also occurred when using code behind.

So the complete solution was to use gong wpf (github) and the solution presented by Omribitan.

解决方案

have you tried GetFileDropList method? you can retreive it from the e.Data in the Drop event.

Something like:

string filename = (string)((DataObject)e.Data).GetFileDropList()[0];

这篇关于使用WPF和数据绑定将文件拖放到应用程序窗口中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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