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

c#-4.0data-bindingdrag and dropwpf

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.

Best Answer

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