UIElement.StartDragAsync(PointerPoint) UIElement.StartDragAsync(PointerPoint) UIElement.StartDragAsync(PointerPoint) UIElement.StartDragAsync(PointerPoint) Method

Definition

Initiates a drag-and-drop operation.

public : IAsyncOperation<DataPackageOperation> StartDragAsync(PointerPoint pointerPoint)
IAsyncOperation<DataPackageOperation> StartDragAsync(PointerPoint pointerPoint) const;
public IAsyncOperation<DataPackageOperation> StartDragAsync(PointerPoint pointerPoint)
Public Function StartDragAsync(pointerPoint As PointerPoint) As IAsyncOperation(Of DataPackageOperation)

Parameters

pointerPoint
PointerPoint PointerPoint

The coordinates of the pointer where the user interacts with the screen, and where the drag visual is attached.

Returns

A DataPackageOperation value that indicates the type of drag-and-drop operation, and whether the operation was successful.

Examples

This example shows how to handle the PointerPressed event on an Image element to initiate a drag operation.

<Image x:Name="myImage" Source="ms-appx:///Assets/Logo.png" 
       PointerPressed="myImage_PointerPressed" />
private async void myImage_PointerPressed(object sender, PointerRoutedEventArgs e)
{
    var pointerPoint = e.GetCurrentPoint(sender as UIElement);
    var dropStatus = await myImage.StartDragAsync(pointerPoint);
    if (dropStatus == DataPackageOperation.Move)
    {
        // App specific code for a "move" operation.
    }
}

Remarks

If you implement custom gesture detection to initiate a drag operation, you can call the StartDragAsync method to programmatically initiate a drag operation on any UIElement. Calling this method results in the DragStarting event being raised. Handle the DragStarting event to specify other properties of the operation, such as the data package and drag visual.

The pointerPoint parameter is the point at which the user interacts with the screen using an input device (touch, mouse, or pen). The drag visual that is shown during the drag operation is attached to the pointer indicated in the caller-provided PointerPoint.

The DataPackageOperation returned by this method indicates whether the drag operation is a move, copy, or link; and whether or not it's a success. This is the same value that's provided by the DropResult property in the DropCompleted event args.

See Also