WPF Drag and Drop

后端 未结 3 625
北恋
北恋 2021-01-07 09:35

How to implement drag & drop for a WPF application? I could open 2 the same apps and drag an object from one to another. Here\'s what I want to drag:



        
3条回答
  •  悲哀的现实
    2021-01-07 10:09

    example WPF Drag and Drop : using vb.net 2010

            
            
                    
            
    

    vb.net code :

     Class mofakfree
    
    
    
            Private Sub label1_MouseDown(ByVal sender as Object, ByVal e as System.Windows.Input.MouseButtonEventArgs)
                'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
                Dim lbl As Label = CType(sender, Label)
                DragDrop.DoDragDrop(lbl, lbl.Content, DragDropEffects.Copy)
            End Sub
    
            Private Sub label2_DragEnter(ByVal sender as Object, ByVal e as System.Windows.DragEventArgs)
                'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
                If e.Data.GetDataPresent(DataFormats.Text) Then
            e.Effects = DragDropEffects.Copy
                Else
                e.Effects = DragDropEffects.None
            End If
    
            End Sub
    
            Private Sub label2_Drop(ByVal sender as Object, ByVal e as System.Windows.DragEventArgs)
                'xxxxxxxxxxxxxxxxxx
                CType(sender, Label).Content = e.Data.GetData(DataFormats.Text)
    
            End Sub
    
        End Class
    

提交回复
热议问题