2014-09-13 146 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