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. 如果元素的AllowDrop屬性為, false則不會引發這個事件。This event is not raised if the element's AllowDrop property is false.

事件會與拖曳來源上GiveFeedback的事件配對。 DragOverThe DragOver event is paired with the GiveFeedback event on the drag source. DragOver在事件處理常式中, 您通常會檢查傳送的資料是否為放置目標可以處理的格式。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. 拖曳來源會在Effects GiveFeedback事件引數的屬性中接收這項資訊, 而且可以設定適當的資料指標, 將意見反應提供給使用者。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 - 委派Delegate DragEventHandler

對應的通道事件為PreviewDragOverThe corresponding tunneling event is PreviewDragOver.

適用於

另請參閱