I was wondering why WPF defines a new and apparently identical version of IDataObject for its drag/drop system?
I have application code which uses the winforms IDataObject which I now need to interoperate with WPF drag/drop events. Would it be safe to simply write an adapter class which implements System.Windows.Forms.IDataObject but passes calls into the actual System.Windows.IDataObject provided by WPF?
Thanks Dan
I found this question when I was trying to debug this problem:
I was dropping into a WinForms application, where inside the Drop event handler, the object I received was a System.Windows.Forms.IDataObject
However, I was using a library to do the heavy lifting of the Drop event, and it expected a object of type System.Windows.IDataObject. I was not able to edit the library source code.
If I tried to simply cast between the types ...
// data is of type System.Windows.Forms.IDataObject
var newData = (System.Windows.IDataObject)data; // debugger exits function after this line of code
... the debugger would just exit the function at that line of code without error. None of the code after that line would execute.
I created a proxy method that I called inside my WinForms event handler. The constructor for System.Windows.DataObject will accept a System.Windows.Forms.DataObject.
public void DropEventProxy(System.Windows.Forms.IDataObject data)
{
System.Windows.IDataObject newData = new System.Windows.DataObject(data);
LibraryDropEventHandler(newData);
}
public string LibraryDropEventHandler(System.Windows.IDataObject data);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With