2014-09-13 96 views
0

这是这个问题的复制here但那个没有足够的答案,所以有人可以帮我解决这个问题吗?WPF - 在拖动拖动之前拖动移动鼠标一组距离

我有一个用户控件被拖动,但这个用户控件也是可点击的,所以有时当你点击你可能会移动鼠标1个像素,它会认为它的拖放。如何设置延迟或使鼠标在拖动之前必须移动5个像素。

任何帮助将非常感激。

〜谢谢!

回答

0

我知道这是晚了,在vb.net,但它可能是有用的。我的例子是拖动TreeViewItems。您首先必须捕获MouseLeftButtonDown事件被触发的位置。

Private _downPoint As Point 
Private Sub TreeViewItem_MouseLeftButtonDown(sender As Object, e As MouseEventArgs) 
     _downPoint = e.GetPosition(Nothing) 
End Sub 

然后在你的MouseMove事件,检查是否已触发的DoDragDrop之前,移动的距离minumim。

Private Sub TreeViewItem_MouseMove(sender As Object, e As MouseEventArgs) 
     _dragObject = sender.DataContext 
     If _dragObject IsNot Nothing AndAlso e.LeftButton = MouseButtonState.Pressed AndAlso MovedMinimumDistance(e) Then 
      DragDrop.DoDragDrop(tb, _dragObject, DragDropEffects.Move) 
     End If 
End Sub 

Private Function MovedMinimumDistance(e As MouseEventArgs) As Boolean 
     Return Math.Abs(e.GetPosition(Nothing).X - _downPoint.X) >= SystemParameters.MinimumHorizontalDragDistance AndAlso 
     Math.Abs(e.GetPosition(Nothing).Y - _downPoint.Y) >= SystemParameters.MinimumVerticalDragDistance 
End Function 

我相信这说明了这个post