DragDrop.Drop DragDrop.Drop DragDrop.Drop Attached Event

定义

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

see AddDropHandler, and RemoveDropHandler
see AddDropHandler, and RemoveDropHandler
see AddDropHandler, and RemoveDropHandler

示例

下面的示例演示 Drop 元素的 Ellipse 事件处理程序。The following example shows the Drop event handler for an Ellipse element. 此代码应用拖放操作的效果。This code applies the effects of the drag-and-drop operation. 它会检查是否将 DataObject 拖动到包含可以转换为 Brush 的字符串数据的椭圆上方。It checks to see if the DataObject being dragged over the ellipse contains string data that can be converted to a Brush. 如果是,将 Brush 应用于椭圆。If so, the Brush is applied to the ellipse. 如果数据无法转换为 Brush,则不执行任何操作。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;
            }
        }
    }
}
Private Sub Ellipse_Drop(ByVal sender As System.Object, ByVal e As System.Windows.DragEventArgs)
    Dim ellipse = TryCast(sender, Ellipse)
    If ellipse IsNot Nothing Then

        ' 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
                Dim newFill As Brush = CType(converter.ConvertFromString(dataString), Brush)
                ellipse.Fill = newFill
            End If
        End If
    End If
End Sub

注解

当对象被置于作为放置目标的元素的边界内时,会引发一次 Drop 事件。The Drop event is raised once when an object is dropped 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. 此事件结束拖放操作。This event ends the drag-and-drop operation.

在 @no__t 0 事件处理程序中,将从 @no__t 中提取传输的数据,并对应用程序所需的数据进行任何处理。In the Drop event handler, you extract the transferred data from the DataObject and perform any processing of the data that your application requires. 若要通知拖动源的效果(例如复制或移动),请在 @no__t 事件处理程序中设置 DragEventArgs.Effects 属性。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. 此属性的值是启动拖放操作的 DoDragDrop 方法的返回值。The value of this property is the return value of the DoDragDrop method that initiated the drag-and-drop operation. 如果返回的值与对 DoDragDrop 的调用中指定的 @no__t 0 不匹配,则不会执行拖放操作。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. @No__t-0 属性的初始值与在 DoDragDrop 方法调用中指定的 @no__t 1 相同。The initial value of the DragEventArgs.Effects property is the same as the allowedEffects specified in the call to the DoDragDrop method. 如果不设置 DragEventArgs.Effects 属性,则返回此初始值,假设发生了 @no__t 1。If you do not set the DragEventArgs.Effects property, this initial value is returned and it is assumed that one the allowedEffects occurred.

路由事件信息Routed Event Information

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

对应的隧道事件为 PreviewDropThe corresponding tunneling event is PreviewDrop.

适用于

另请参阅