views:

24

answers:

2

I'm dragging UserControl objects from one Canvas to another with the intention of dropping there. When mousing over the destination, the dragged object actually goes under it. I get no DragEnter, DragOver or DragLeave events. If I drop the object there, I get no Drop event.

My root object is a border, then a grid. The grid covers the entire browser client area. It has 8 columns. In each of the columns there is a canvas that is placed by the XAML.

Example of odd behavior: When I drag an item from column 3 to column 4 (or any greater) the object slides under the canvas. If I drag from column 3 to column 2 (or any lesser) the object slides over the top. So it appears that zorder is affected by the order of creation of the Canvases. Can someone clarify this?

The Canvas objects in each of the columns have DragEnter/Leave events associated but none of them fire, whether the object goes over or under the Canvas.

I found that a Canvas must have a background in order to get mouse events. Each of the Canvases in the columns have a Background. The mouse events fire if I'm not dragging anything.

I'm nearing the end of my rope and sure would appreciate some assistance.

Thanks, Greg

A: 

Is AllowDrop set to true on your Canvas(es)?

toxoplasmotic
A: 

@toxoplasmotic: yes.

RE: Getting no events firing. As it turns out, the Drag events are wired up, but provide no functionality.

RE: Dragging under/over the various drop target canvases. There seems to be some kind of zorder that's established by the 'natural order' of the creation of the canvases.

But these things aren't really the important points.

Solution #1. With Silverlight 3, there was introduced a new Expression Blend Behavior: MouseDragElementBehavior. It encapsulates quite a bit of drag/drop functionality. It is preserved in SL4.

Solution #2. On codeplex there is a Silverlight Toolkit that has (in the experimental stages) another very nice encapsulation of drag/drop functionality. It appears that this one might require a little extra coding if you're not working with list boxes and tree views, etc.

Solution #3. But the capper is this: it's pretty easy to do drag/drop using Alex Van Beek's fairly well documented code. It is here: http://blogs.infosupport.com/blogs/alexb/archive/2009/09/07/A-complete-Silverlight-3-drag-and-drop-solution.aspx

The key to success is to disassociate the dragged object from its parent and associate it with an abstraction of the browser window, usually the root object or another canvas that's transparent. The difficulty (not so difficult) is to keep the various coordinate systems in sync. (the "from" canvas, "to" canvas, dragged object)

Cheers! Greg

Greg Oliver