Drag and Drop in WPF

I have a WPF application with drag-n-drop inmplementation ... Whenever I drag a tree item on Grid, it is handled by the DragDropEvent of this Grid, but every time it receives it fires twice , what could be the reason?

Below is the code to perform a drag and drop drag on TreeView:

 void treeViewGroups_MouseMove(object sender, MouseEventArgs e)
 {
   try
   {
     if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed)
     {
        Point position = e.GetPosition(null);
        if (Math.Abs(position.X - this.startPoint.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(position.Y - this.startPoint.Y) > SystemParameters.MinimumVerticalDragDistance)
        {
          DataRowView treeViewItem = this.treeViewGroups.SelectedItem as DataRowView;
          if (treeViewItem != null)
          if ((treeViewItem.Row.Table.TableName == "TableGroup"))
          {
             ViewTaxSCConstants.dragElement = treeViewItem;
             Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Render, new System.Threading.ParameterizedThreadStart(DoDragDrop), treeViewItem);                                
           }
        }
     }
}
+3
source share
2 answers

: MouseMove drop TreeViewItems. , ( - , ).

, e.Handled = true Drop.

+3

, Drag and Drop

darg drop

MouseMove MouseLeftButtonDown

, , DataObject, , .

, DoDragDrop()

AllowDrop True , .

DragEnter, . , GetDataPresent() . , Effect , .

, DragDrop. , GetData() Data, .

-1

Source: https://habr.com/ru/post/1716568/


All Articles