Skip to content
slluis edited this page Mar 9, 2012 · 7 revisions

This document explains how Drag & Drop works in XWT, and which methods and events are involved.

Starting a drag operation manually

Drag Source
1

The source calls Widget.CreateDragOperation to start a new drag operation. This method returns a DragOperation object which can be used to set the data to be dragged, and the drag icon to be used. For example:

var dragOper = someWidget.CreateDragOperation ();
dragOper.Data.AddValue ("Hi there!");
var img = Image.FromResource (GetType(), "someNiceIcon.png");
dragOper.SetDragImage (img, 0, 0);
dragOper.AllowedActions = DragDropAction.All;
dragOper.Start ();

Starting a drag operation automatically

Drag Source
1

The source calls Widget.SetDragSource set a widget as an automatic drag source. A drag operation will be created when the user clicks and drags on the widget. For example:

someWidget.SetDragSource (TransferDataType.Text);
2

When the user clicks and drags on the widget XWT fires the DragStarted event on the widget. The drag operation can be set up in the handler for the event. For example:

someWidget.SetDragSource (TransferDataType.Text);
someWidget.DragStarted += delegate (object sender, DragStartedEventArgs args) {
    var dragOper = args.DragOperation;
    dragOper.Data.AddValue ("Hi there!");
    var img = Image.FromResource (GetType(), "someNiceIcon.png");
    dragOper.SetDragImage (img, 0, 0);
    dragOper.AllowedActions = DragDropAction.All;
}

Dragging over a target

This sequence starts when the users moves the mouse over a widget while dragging.

Drag Source Drop Target
1

The DragOverCheck is raised.

The handler of the event can specify in AllowedAction which drop operations are supported, or None if drop is not supported. If AllowedAction is set to something other than Default the mouse cursor is updated to reflect the new state and the sequence ends here (DragOver won't be raised in this case)

2 If the DragOver event is subscribed in the target, XWT retrieves the data from the source. If the DataRequestCallback was set in the drag data source, it will be invoked now.
3

The DragOver event is raised.

The handler of the event must specify in AllowedAction which drop operations are supported, or None if drop is not supported. The mouse cursor is updated to reflect the new state.

4 At any point of the sequence, if the mouse is moved outside of the widget the DragLeave event is raised.

Dropping

This sequence starts when the user releases the mouse button while over the target widget.

Drag Source Drop Target
1

When the user drops over the widget, the DragDropCheck event is raised.

2 XWT retrieves the drag data from the source. If the DataRequestCallback was set in the drag data source, it will be invoked now.
3 The DragDrop event is raised.
4

The Finished event is raised in the source drag operation object.

The DeleteSource property of the event arguments is set to True if the drag operation was a Move.

Clone this wiki locally