Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 716
Onur Avatar asked Oct 14 '13 08:10

Onur


1 Answers

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];
like image 144
Omri Btian Avatar answered Nov 15 '22 10:11

Omri Btian