Drag and drop a file into application window using WPF and data binding

≡放荡痞女 提交于 2020-01-01 05:40:29

问题


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.


回答1:


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];


来源:https://stackoverflow.com/questions/19355774/drag-and-drop-a-file-into-application-window-using-wpf-and-data-binding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!