Questo articolo è stato tradotto automaticamente. Per visualizzare l'articolo in inglese, selezionare la casella di controllo Inglese. È possibile anche visualizzare il testo inglese in una finestra popup posizionando il puntatore del mouse sopra il testo.
Traduzione
Inglese

DragDrop.Drop Evento associato

 

Data di pubblicazione: ottobre 2016

Si verifica quando un oggetto viene rilasciato entro i limiti di un elemento che funge da destinazione del rilascio.

Spazio dei nomi:   System.Windows
Assembly:  PresentationCore (in PresentationCore.dll)

See AddDropHandler, RemoveDropHandler

The E:System.Windows.DragDrop.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 P:System.Windows.UIElement.AllowDrop property is false. This event ends the drag-and-drop operation.

In the E:System.Windows.DragDrop.Drop event handler, you extract the transferred data from the T:System.Windows.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 P:System.Windows.DragEventArgs.Effects property in the E:System.Windows.DragDrop.Drop event handler. The value of this property is the return value of the M:System.Windows.DragDrop.DoDragDrop(System.Windows.DependencyObject,System.Object,System.Windows.DragDropEffects) 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 M:System.Windows.DragDrop.DoDragDrop(System.Windows.DependencyObject,System.Object,System.Windows.DragDropEffects), the drag-and-drop operation is not performed. The initial value of the P:System.Windows.DragEventArgs.Effects property is the same as the allowedEffects specified in the call to the M:System.Windows.DragDrop.DoDragDrop(System.Windows.DependencyObject,System.Object,System.Windows.DragDropEffects) method. If you do not set the P:System.Windows.DragEventArgs.Effects property, this initial value is returned and it is assumed that one the allowedEffects occurred.

Identifier field

DropEvent

Routing strategy

Bubbling

Delegate

DragEventHandler

The corresponding tunneling event is E:System.Windows.DragDrop.PreviewDrop.

The following example shows the E:System.Windows.DragDrop.Drop event handler for an T:System.Windows.Shapes.Ellipse element. This code applies the effects of the drag-and-drop operation. It checks to see if the T:System.Windows.DataObject being dragged over the ellipse contains string data that can be converted to a T:System.Windows.Media.Brush. If so, the T:System.Windows.Media.Brush is applied to the ellipse. If the data cannot be converted to a T:System.Windows.Media.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;
            }
        }
    }
}
Torna all'inizio
Mostra: