Skip to content

Latest commit

 

History

History
55 lines (39 loc) · 2.93 KB

uielement_startdragasync_369751260.md

File metadata and controls

55 lines (39 loc) · 2.93 KB
-api-id -api-type
M:Windows.UI.Xaml.UIElement.StartDragAsync(Windows.UI.Input.PointerPoint)
winrt method

Windows.UI.Xaml.UIElement.StartDragAsync

-description

Initiates a drag-and-drop operation.

-parameters

-param 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.

-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.

-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.
    }
}

-see-also

DragStarting, CanDrag, Drag and drop sample (Windows 10)