I have a WPF user control hosted in a Windows Forms Application and the control contains a WPF image ( among other things ) and was wondering whether it is possible to let the user drag this image to outside th开发者_开发百科e app ( to windows explorer, to the desktop , to a folder) ?
Regards, MadSeb
It is possible - when you start the drag/drop operation (DoDragDrop
), you pass in a IDataObject - this is the key to allowing what you want.
The easy way to do this is to use a normal DataObject with DataFormats.FileDrop
, and give it the name of the file. Unfortunately this is not quite what you want, but the quick and dirty way for you to do this would be to create a temporary file and pass that as the name. Done.
The hard way is to implement IDataObject and serve up a virtual (in-memory) file containing the image you want. There is an article on codeplex about transferring virtual files to windows explorer via drag-drop that should get you started. Also see Drag and drop virtual files using IStream
精彩评论