Drag drop from Winforms to WPF problem

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
 
Joined
Jul 17, 2009
Messages
1
Reaction score
0
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 .

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top