views:

23

answers:

1

Silverlight 4 now provides controls to handle Drag and Drop actions. All the Target Controls seem to inherit from DragDropTarget Like so

public class MyControlDragDropTarget : DragDropTarget<TItemsControlType,TItemsContainerType>

. . .

A number of controls have pre-defined DragDropTargets including the DataGrid, ListBox, Panels

Which is all very well, but I want to drag and drop from a grid not a datagrid, and there is no pre-defined one for a normal grid.

I actually want to drag a given row from the grid, but without a Container Type for a Grid I cannot work out how to define a DragDropTarget control for the grid.

Only way I can think is instead of using a grid - I use a listbox (for which there is a DragDropTarget) and then place a StackPanel or Grid in each row (which has one row of 'n' columns)

Anyone got any ideas

Ta in advance

A: 

A "normal grid" is simply another form of panel, there is no need for specialised DragDropTarget for the Grid, the existing PanelDragDropTarget is sufficient for a "normal grid".

Its important grasp that the Grid does not support the concept of "rows containing cells containing UI elements". The rows and columns of a Grid are entirely equal and are defined purely for layout purposes. UIElement children of a Grid are laid out entirely independently of each other, there is no concept of a set of values belonging to either a column or a row that can be moved or operated on as a group (like picking up a row and dragging it).

Sounds like you have already got an answer for yourself, use the ListBox instead.

BTW, DragDropTarget isn't provided by Silverlight 4 but rather the Silverlight Toolkit. This is an important distinction because the current quality band assigned to DragDropTarget is "Experimental". You need to think carefully about this if you want to use such code in some production release of your own.

AnthonyWJones
Ta - I'll do that but was wondering if having in effect 1 grid per row would be prohibitive. Although I'm likely to create a user control for the child objects - allowing for meta data to be stored against them.
paulschapman
@paulschapman: Standard `Grid` elements are lightweight so if I'm understanding you correctly having one Grid per row would not be prohibitive.
AnthonyWJones