PC Review


Reply
Thread Tools Rate Thread

Drag drop from Winforms to WPF problem

 
 
Robert
Guest
Posts: n/a
 
      3rd Feb 2009
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
 
Reply With Quote
 
 
 
 
New Member
Join Date: Jul 2009
Posts: 1
 
      17th Jul 2009
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 .

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
WinForms Drag Drop with Custom Image/Cursor Lloyd Sheen Microsoft VB .NET 0 15th Dec 2008 11:52 PM
Drag and Drop Column headers (drag and drop using wndProc?) KamiiKoneko@gmail.com Microsoft Dot NET Framework Forms 0 17th Dec 2007 02:28 PM
Drag drop events in .Net 2.0's WebBrowser control in winforms Vin Microsoft Dot NET Framework 1 12th Mar 2006 05:36 PM
Drag drop events in .Net 2.0's WebBrowser control in winforms Vin Microsoft Dot NET Framework Forms 0 6th Mar 2006 05:45 PM
Drag drop events in .Net 2.0's WebBrowser control in winforms Vin Microsoft C# .NET 0 6th Mar 2006 05:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:03 PM.