Dieser Artikel wurde maschinell übersetzt. Wenn Sie die englische Version des Artikels anzeigen möchten, aktivieren Sie das Kontrollkästchen Englisch. Sie können den englischen Text auch in einem Popupfenster anzeigen, indem Sie den Mauszeiger über den Text bewegen.
Übersetzung
Englisch

DragDrop.DragOver Angefügtes Ereignis

 

Veröffentlicht: Oktober 2016

Tritt fortlaufend auf, während ein Objekt innerhalb der Grenzen eines Elements gezogen wird, das als Ablageziel fungiert.

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

See AddDragOverHandler, RemoveDragOverHandler

This event is raised continuously while a dragged object is 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.

The E:System.Windows.DragDrop.DragOver event is paired with the E:System.Windows.DragDrop.GiveFeedback event on the drag source. In the E:System.Windows.DragDrop.DragOver event handler, you typically check that the transferred data is in a format that the drop target can process. You can also check whether any modifier keys are pressed, which typically indicates whether the user intends a move or a copy action. After these checks are performed, you set the P:System.Windows.DragEventArgs.Effects property to notify the drag source what effect dropping the data will have. The drag source receives this information in the P:System.Windows.GiveFeedbackEventArgs.Effects property of the E:System.Windows.DragDrop.GiveFeedback event arguments, and can set an appropriate cursor to give feedback to the user.

Identifier field

DragOverEvent

Routing strategy

Bubbling

Delegate

DragEventHandler

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

The following example shows the E:System.Windows.DragDrop.DragOver event handler for an T:System.Windows.Shapes.Ellipse element. This code 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, it sets the P:System.Windows.DragEventArgs.Effects property to F:System.Windows.DragDropEffects.Copy. This indicates to the drag source that the data can be copied to the ellipse. If the data cannot be converted to a T:System.Windows.Media.Brush, the P:System.Windows.DragEventArgs.Effects property is set to F:System.Windows.DragDropEffects.None. This indicates to the drag source that the ellipse is not a valid drop target for the data.

private void ellipse_DragOver(object sender, DragEventArgs e)
{
    e.Effects = DragDropEffects.None;

    // 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, allow copying.
        BrushConverter converter = new BrushConverter();
        if (converter.IsValid(dataString))
        {
            e.Effects = DragDropEffects.Copy | DragDropEffects.Move;
        }
    }
}
Zurück zum Anfang
Anzeigen: