I've got a control with rectangles in a grid. I can drag rectangles from one cell to another within the grid. But I also need to double-click on a rectangle to bring up an edit dialog. The issue here is that just pressing the left mouse button on the rectangle will initiate a MouseMove
event and cause the DragDrop
to initiate when it's not wanted.
Here's the MouseMove
and MouseDoubleClick
event handlers:
Dim IsDragging As Boolean = False
Private Sub SchedItem_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
If IsDragging Then Exit Sub
If e.LeftButton = MouseButtonState.Pressed Then
Dispatcher.InvokeAsync(Sub()
IsDragging = True
DragDrop.DoDragDrop(Me, Me, DragDropEffects.Move)
IsDragging = False
End Sub)
End If
End Sub
Private Sub SchedItem_PreviewMouseDoubleClick(sender As Object, e As MouseButtonEventArgs) Handles Me.PreviewMouseDoubleClick
itmEditTask_Click(Nothing, Nothing)
e.Handled = True
End Sub
I tried not initiating the MouseMove
by attempting to determine the distance the mouse had traveled since the MouseLeftButtonDown
event. But the x & y numbers are all over the place and I can't reliably set a threshold value. Here's that code:
Private mPos As Point
Private Sub SchedItem_MouseLeftButtonDown(sender As Object, e As MouseButtonEventArgs) Handles Me.MouseLeftButtonDown
mPos = Mouse.GetPosition(Nothing)
End Sub
Private Function IsReallyMouseMove() As Boolean
Dim pPos As Point = Mouse.GetPosition(Nothing)
Debug.WriteLine(Math.Abs(mPos.X - pPos.X) & ", " & Math.Abs(mPos.Y - pPos.Y))
IsReallyMouseMove = Math.Abs(mPos.X - pPos.X) > 10 OrElse Math.Abs(mPos.Y - pPos.Y) > 10
End Function
So I'm hoping someone has done this and can provide some direction.
best way - redesign. Make you item draggable by some object in item element. (Maybe little dot with different drag cursor) Other area will handle double click.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.