Reputation: 913
I start the operation like this:
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" is a custom class called, CellContainer, which is really a canvas with added properties.
I handle the drop like this:
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
The problem is that e.OriginalSource shows up as a Canvas, not a CellContainer, and cTarget is set to Nothing. How can I pass the entire CellContainer (not just the ObjectKey) from the Drag to the Drop?
Upvotes: 0
Views: 246
Reputation: 913
Solved it like this:
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
Upvotes: 0