DragDrop.DragOver DragDrop.DragOver DragDrop.DragOver Attached Event

定义

在将对象拖入作为放置目标的元素边界时持续发生。Occurs continuously while an object is dragged within the bounds of an element that is acting as a drop target.

see AddDragOverHandler, and RemoveDragOverHandler
see AddDragOverHandler, and RemoveDragOverHandler
see AddDragOverHandler, and RemoveDragOverHandler

示例

下面的示例演示 DragOver 元素的 Ellipse 事件处理程序。The following example shows the DragOver event handler for an Ellipse element. 此代码检查是否已将 DataObject 拖动到包含可以转换为 Brush 的字符串数据的椭圆上方。This code checks to see if the DataObject being dragged over the ellipse contains string data that can be converted to a Brush. 如果是,它会将 DragEventArgs.Effects 属性设置为 CopyIf so, it sets the DragEventArgs.Effects property to Copy. 这将向拖动源指示可以将数据复制到椭圆。This indicates to the drag source that the data can be copied to the ellipse. 如果数据无法转换为 Brush,则将 DragEventArgs.Effects 属性设置为 NoneIf the data cannot be converted to a Brush, the DragEventArgs.Effects property is set to 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;
        }
    }
}
Private Sub Ellipse_DragOver(ByVal sender As System.Object, ByVal e As System.Windows.DragEventArgs)
    e.Effects = DragDropEffects.None

    ' If the DataObject contains string data, extract it.
    If e.Data.GetDataPresent(DataFormats.StringFormat) Then
        Dim dataString = e.Data.GetData(DataFormats.StringFormat)

        ' If the string can be converted into a Brush, convert it.
        Dim converter As New BrushConverter()
        If converter.IsValid(dataString) Then
            e.Effects = DragDropEffects.Copy Or DragDropEffects.Move
        End If
    End If
End Sub

注解

当拖动的对象在充当拖放目标的元素边界内时,将连续引发此事件。This event is raised continuously while a dragged object is within the bounds of an element that is acting as a drop target. 如果元素的 @no__t 0 属性 @no__t 为-1,则不会引发此事件。This event is not raised if the element's AllowDrop property is false.

@No__t-0 事件与拖动源上的 @no__t 1 事件配对。The DragOver event is paired with the GiveFeedback event on the drag source. 在 @no__t 0 事件处理程序中,通常会检查传输的数据是否是拖放目标可以处理的格式。In the 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. 执行这些检查后,设置 DragEventArgs.Effects 属性以通知拖动源放置数据将产生的效果。After these checks are performed, you set the DragEventArgs.Effects property to notify the drag source what effect dropping the data will have. 拖动源会在 @no__t 1 事件参数的 Effects 属性中接收此信息,并可以设置相应的光标以向用户提供反馈。The drag source receives this information in the Effects property of the GiveFeedback event arguments, and can set an appropriate cursor to give feedback to the user.

路由事件信息Routed Event Information

标识符字段Identifier field DragOverEvent
路由策略Routing strategy 冒泡Bubbling
委托Delegate DragEventHandler

对应的隧道事件为 PreviewDragOverThe corresponding tunneling event is PreviewDragOver.

适用于

另请参阅