IDataObject WPF Winforms Interop

I encountered  a strange problem today when writing an App which involved WPF and Winform interop. While drag dropping from a winforms control into a WPF control,  the WPF control gives you System.Windows.IDataObject in its drag event args. But I needed the dataObject as a System.Windows.Forms.IDataObject object. After looking for solutions to convert , I figured out this tiny bit of code will takee care of it 🙂
 
System.Windows.Forms.DataObject winformDataobject = new System.Windows.Forms.DataObject();
foreach (string format in wpfDataObject.GetFormats())
{
         winformDataobject.SetData(format, wpfDataObject.GetData(format));
}
Advertisements
This entry was posted in WPF. Bookmark the permalink.

56 Responses to IDataObject WPF Winforms Interop

  1. Alvaro says:

    It worked!!, thanks.

  2. Peter says:

    This only works for primitive types, for more complicated objects, seehttp://danglypointers.spaces.live.com/blog/cns!99725B524CE81CA3!146.entry

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s