简体   繁体   中英

Drag and Drop from Silverlight to WPF

I'm wondering if anyone has been able to Drag some item (let's say an image with an id) in silverlight and drop it in a listbox in WPF.

If you have please help ;)

Thanks, S

Drag drop to a Silverlight application from other surfaces outside of the Silverlight application is available only in Silverlight 4 and is limited to a file list payload.

Hence the only drag drop function you may be able to achieve between a WPF app and Silverlight is if you initiate the drag operation in the WPF app and include a standard file list as part of the Data attached to the drag.

I agree with @AnthonyWJones. Silverlight does not have the System.Windows.DragDrop.DoDragDrop method that WPF has, so you cannot initiate a "real" drag&drop. You can drag & drop controls within your app, but it is not possible to do what you are asking.

Anthony and Timores are correct in their responses, but I'll try to get creative with some ideas here:

  • If you can leverage the same backend services, perhaps when a drag begins (MouseDown + MouseMove) you could send a chunk of XAML up to a service to store/cache the content, and when a drag ends on the other application (MouseEnter + MouseUp over the drop target), you could call that service to pull down the cached content
  • In Silverlight 4, you have access in the local file system to the users "My" folders. You may be able to use a temporary file and the drag begin/drag end events described above to transfer you XAML chunk from one app to another. Refer to http://timheuer.com/blog/archive/2009/11/18/whats-new-in-silverlight-4-complete-guide-new-features.aspx#localfiles
  • If you are wanting to drag and drop text, you might be able to utilize the clipboard. So when a drag begins, copy text into the clipboard. When you end your drag in the other app, read from the clipboard and add the contents to the drop target

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM