DragDrop.Drop 附加事件
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在作为放置目标的元素的边界内删除对象时发生。
see AddDropHandler, and RemoveDropHandler
see AddDropHandler, and RemoveDropHandler
see AddDropHandler, and RemoveDropHandler
示例
以下示例显示了 Drop 元素 Ellipse 的事件处理程序。 此代码应用拖放操作的效果。 它会检查被拖动到椭圆上是否 DataObject 包含可转换为 a Brush的字符串数据。 如果是,则 Brush 应用于椭圆。 如果无法将数据转换为 a Brush,则不执行任何操作。
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当对象在充当放置目标的元素的边界内删除时,将引发该事件。 如果元素 AllowDrop 的属性为 false.,则不引发此事件。 此事件结束拖放操作。
在事件处理程序中 Drop ,从应用程序所需的数据中提取传输的数据 DataObject 并执行任何处理。 若要通知拖放效果的拖动源(如复制或移动),请在 DragEventArgs.Effects 事件处理程序中 Drop 设置属性。 此属性的值是启动拖放操作的方法的 DoDragDrop 返回值。 如果返回的值与调用DoDragDrop中指定的值allowedEffects不匹配,则不执行拖放操作。 属性的初始值与allowedEffects调用DoDragDrop方法中指定的值DragEventArgs.Effects相同。 如果未设置该 DragEventArgs.Effects 属性,则返回此初始值,并假定发生了该 allowedEffects 值。
路由事件信息
| 物品 | 价值 |
|---|---|
| 标识符字段 | DropEvent |
| 路由策略 | 鼓 泡 |
| 委托人 | DragEventHandler |
相应的隧道事件为 PreviewDrop。