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
Hi,
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,
-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?