How to implement drag-and-drop from a small node of a WPF element in a Winforms application?

In our application, we place a small WPF list inside the Element node, we implement drag and drop using the PreviewMouseDown event ...

   private void Border_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            // Get the current mouse position
            Point mousePos = e.GetPosition(null);
            Vector diff = startPoint - mousePos;

            if (e.LeftButton == MouseButtonState.Pressed &&
                Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance &&
                Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)
            {
                OnDragStarted(e);                
            } 

        }

The problem we see is that when I drag and drop an item quickly and quickly, the WPF control fires only one PreviewMouseMove event before the mouse leaves Elementhost, so the drag operation does not start until the mouse returns to Elementhost and one more PreviewMouseMove event.

Is there a reliable way to handle this case?

+3
source share
1 answer

. , , . Mouse.Capture() WPF.

+2

All Articles