views:

38

answers:

2

I have a program with two WPF treeviews that allow dragging and dropping between the two. The problem is, it can be annoying to open / close items on the treeviews because moving the mouse just one pixel while holding the left mouse button triggers the drag / drop functionality. Is there some way to specify how far the mouse should move before it's considered a drag / drop?

Thanks!

A: 

Just build a little buffer into your code that determines when the drag starts.

  1. flag mouse down
  2. on mouse move - check for mouse down.. if yes, check to see if its moved farther than whatever buffer you specify (3 pixels is probably good)
  3. if it has, start the drag.
mdm20
+1  A: 

There's a system parameter for this. If you have

Point down = {where mouse down event happened}
Point current = {position in the MouseMove eventargs}

then the mouse has moved the minimum drag distance if

Math.Abs(current.X - down.X) >= SystemParameters.MinimumHorizontalDragDistance ||
Math.Abs(current.Y - down.Y) >= SystemParameters.MinimumVerticalDragDistance)
vanmelle