Hi
I would like to implement a functionality that would allow me to drag an html element from the page (like image) over my silverlight container which includes a grid and change the mouse indicator to hint that it would be possible to drop an item into a cell of the grid. On dropping, some part of the information (like an ID value from img tag) would be pasted into the cell.
Can you please explain how this can be achieved, preferably with some example code.
Thanks
Mention of image element was for discussion sake, I'm actually testing with selecting some text in a textarea element and dragging it to the Silverlight area, but it doesn't seem to make any difference.
Hi,
I'm not exactly sure. I can drag and drop files from my desktop, no problem, and all the events fire. But when it comes to images from the browser, the Drop never fires, regardless of the FrameworkElement that i'm dropping it on.
I suppose it could be a security issue, but i'm not really sure.
-SteveZ
Thanks, Steve
I'm trying a simple test to verify these events with following code ("Answers" is a xamGrid in the canvas):
Answers.DragEnter += (s, e) => Answers.BorderBrush = new SolidColorBrush(Colors.Green); Answers.DragLeave += (s, e) => Answers.BorderBrush = new SolidColorBrush(Colors.Gray); Answers.Drop += (s, e) => Answers.BorderBrush = new SolidColorBrush(Colors.Red);
Doing this makes the grid get the green border when dragging something over, gray border when dragging away from it, but no red color on Drop ever comes up. Any idea why?
I'm not 100% sure its possible, as this is more of a platform question.
However, in Sl 4, the AllowDrop property was introduced, which allows you to hook into some additional events available on all UIElements. Specifically : DragEnter, DragLeave, DragOver and Drop.
If you set AllowDrop to true, i'm pretty sure the event will fire when you drag an HTML img over the grid, however, i'm not sure if you'll be able to access the data.
Here are a few links i found that might be helpful:
http://en.baydachnyy.com/2010/02/02/silverlight-4-drag-drop/
http://msdn.microsoft.com/en-us/library/system.windows.uielement.allowdrop(v=vs.95).aspx
Hope this helps,