我开始这样的操作:
Public Sub cLinkOut_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
'Trace.WriteLine("mousedown: " & ObjectKey)
DragDrop.DoDragDrop(TryCast(Me, CellContainer), ObjectKey, DragDropEffects.All)
e.Handled = True
End Sub
" ME"是一个名为CellContainer的自定义类,它实际上是一个添加了属性的画布。
我像这样处理掉落:
Public Sub cLinkIn_Drop(ByVal sender As Object, ByVal e As DragEventArgs)
Dim cSource As String = e.Data.GetData(DataFormats.StringFormat)
Dim cTarget As String = TryCast(e.OriginalSource, CellContainer).ObjectKey
Trace.WriteLine("srce: " & cSource & ", targ: " & cTarget)
e.Handled = True
End Sub
问题是e.OriginalSource显示为Canvas,而不是CellContainer,cTarget设置为Nothing。如何将整个CellContainer(不仅仅是ObjectKey)从Drag拖到Drop?
答案 0 :(得分:0)
解决这个问题:
Public Sub cLinkOut_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
Dim data As DataObject = New DataObject(DataFormats.Serializable, Me)
DragDrop.DoDragDrop(CType(e.Source, DependencyObject), data, DragDropEffects.Copy)
e.Handled = True
End Sub
Public Sub cLinkIn_Drop(ByVal sender As Object, ByVal e As DragEventArgs)
Dim c As CellContainer = CType(e.Data.GetData(DataFormats.Serializable), CellContainer)
Dim cSource As String = c.ObjectKey
Dim cTarget As String = Me.ObjectKey
Trace.WriteLine("srce: " & cSource & ", targ: " & cTarget)
e.Handled = True
End Sub