DragSource in a DropTarget but parent is a grid (related to auto size problems)

Feb 12, 2010 at 7:53 PM
Edited Feb 12, 2010 at 8:13 PM

I think I've missed something significant and basic, but despite my best efforts I can't seem to locate a solution to my problem.

I've been having some auto-sizing problems in my project. I have a ScrollViewer set as a DragSource's content, the DragSource is set as the content to a DropTarget like so:

ScrollViewer sv = new ScrollViewer();

DragSource ds = new DragSource(){Content = sv};

DropTarget dt = new DropTarget(){Content = ds};

Strangely, the DragSource's Parent appears to be a Grid. Even stranger is that the Grid doesn't inherit it's size from the DropTarget (in fact the Grid has no parent!). The consequence of this is that the DragSource inherits it's size from it's content, the ScrollViewer, but the ScrollViewer has no idea how large a Space the DropTarget is in.

A work around would be to set the ScrollViewer's size equal to the size of the DropTarget (Since the DropTarget knows what size area it's it), but there is a problem with this: The DropTarget's Height and Width are both set to Not A Number (which, I think, is that value that allows the item to use the Horizontal and Vertical Alignment Stretch). The DropTarget's DropBorder (the blue rectangle that appears when a DragSource is hovered over a DropTarget) knows the size of the space it's in and fits it appropriately, but these dimentions are not available through the DropTarget since the DropBorder's size is not made available.

I have tried setting the DropSource's Horizontal and Vertical Alignments to Stretch but this doesn't do anything. I have tried setting the DropSources's Parent (the autogenerated grid's) Horizontal and Vertical Alignments to Stretch but this doesn't do anything.

 

So the question is, why the Grid? It disconnects the DropTarget from the DragSource.

 

 I've seen a few other discussions of people having problems with sizing in their projects and I believe this may also be the source of their problems.