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

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

问题描述

我想能够将文件(例如从Desktop或Explorer)拖放到WPF应用程序的主窗口中。



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



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



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



编辑:gong-wpf-dragdrop工作(一个小的修复后),使用代码时也出现问题。


$ b $所以完整的解决方案是使用gong wpf( github )和解决方案由Omribitan提供。

解决方案

你尝试过 GetFileDropList 我方法?您可以从删除事件。



如下:

  string filename =(string)(( 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天全站免登陆