Drag & Drop with DataPresenter family controls

John Doe / Tuesday, July 28, 2009

This is a sample implementation how to Drag and Drop DataRecord for controls from the DataPresenter family controls - XamDataPresenter, XamDataGrid, XamDataCarousel. The sample uses the standard WPF events for drag-drop. The Drag&Drop preview is displayed in the Adorner layer.

To enable drag-drop functionality, first you need to allow it, by setting the AllowDrop property of the element that you wish to drop over. The Drag begins by calling the DragDrop.DoDragDrop(...) method and passing the drag source element, the data being dragged (an instance of DataObject class) and DragDropEffects.

When the dragging has started, you can display a preview of the element being dragged (in this case a DataRecordPresenter) in the Adorner layer. The easiest way to do this is using a VisualBrush to pait an area (for example a Rectangle) with the DataRecordPresenter.

For anyone who wants more information on how the Drag-Drop works from start to end, you can take a look at this great article on this here.

The full sample you can find in the attachments of this blog post.