Drag drop from Winforms to WPF problem

  • Thread starter Thread starter Robert
  • Start date Start date
R

Robert

I am using WindowsFormsHost to host a Winforms control in a .NET 3.5 WPF
application. I can drag and drop a simple string from the Winforms control to
a WPF control.
However, when I pass a generic collection to the DoDragDrop() method of the
WinformsControl, the WPF control gets a return value of null from the
DragEventArgs.Data.GetData() method, even though I can see in the debugger
that DragEventArgs.Data contains data of the type of my generic collection.

What am I missing?


snippet from Winforms control:
private void ListViewItemDrag(object sender, ItemDragEventArgs e)
{
List<Dictionary<String, String>> list = //get data to drag from
control
DoDragDrop(list, DragDropEffects.Move);
....

snippet from drag destination wpf control:

public void TreeViewDrop(object sender, DragEventArgs e)
{

List<Dictionary<String, String>> list = (List<Dictionary<String,
String>>)e.Data.GetData(typeof(List<Dictionary<String, String>>));
//after this call, list is null even though Data seems to contain object of
desired typed.

Thanks,
Robert
 
I searched the internet over and couldn't find the answer to this, so I thought I'd help out.

There is a very simple work around... instead of using the WPF controls DragDrop methods, just create a new winforms control inside your WPF code... and use it like this:

System.Windows.Forms.Control C = new System.Windows.Forms.Control();

C.DoDragDrop(task, System.Windows.Forms.
DragDropEffects.Copy);

then WPF and winforms aren't even talking -- you get the same result, however you aren't passing the sending control... which I'm sure you could create a workaround around for if needed .

 
Back
Top