Drop Attached Event

DragDrop.Drop Attached Event


Occurs when an object is dropped within the bounds of an element that is acting as a drop target.

Namespace:   System.Windows
Assembly:  PresentationCore (in PresentationCore.dll)

See AddDropHandler, RemoveDropHandler

The Drop event is raised once when an object is dropped within the bounds of an element that is acting as a drop target. This event is not raised if the element’s AllowDrop property is false. This event ends the drag-and-drop operation.

In the Drop event handler, you extract the transferred data from the DataObject and perform any processing of the data that your application requires. To notify the drag source of the effect of the drop, such as a copy or move, set the DragEventArgs.Effects property in the Drop event handler. The value of this property is the return value of the DoDragDrop method that initiated the drag-and-drop operation. If the value that is returned does not match one of the allowedEffects specified in the call to DoDragDrop, the drag-and-drop operation is not performed. The initial value of the DragEventArgs.Effects property is the same as the allowedEffects specified in the call to the DoDragDrop method. If you do not set the DragEventArgs.Effects property, this initial value is returned and it is assumed that one the allowedEffects occurred.

Identifier field


Routing strategy




The corresponding tunneling event is PreviewDrop.

The following example shows the Drop event handler for an Ellipse element. This code applies the effects of the drag-and-drop operation. It checks to see if the DataObject being dragged over the ellipse contains string data that can be converted to a Brush. If so, the Brush is applied to the ellipse. If the data cannot be converted to a Brush, no action is performed.

private void ellipse_Drop(object sender, DragEventArgs e)
    Ellipse ellipse = sender as Ellipse;
    if (ellipse != null)
        // If the DataObject contains string data, extract it.
        if (e.Data.GetDataPresent(DataFormats.StringFormat))
            string dataString = (string)e.Data.GetData(DataFormats.StringFormat);

            // If the string can be converted into a Brush, 
            // convert it and apply it to the ellipse.
            BrushConverter converter = new BrushConverter();
            if (converter.IsValid(dataString))
                Brush newFill = (Brush)converter.ConvertFromString(dataString);
                ellipse.Fill = newFill;
Return to top
© 2016 Microsoft