开发者

UIElement.PreviewMouseMove or not MouseMove... that is the question

WPF,

MSDN:

UIElement.PreviewMouseMove Event

Occurs when the mouse pointer moves while the mouse pointer is over this element.

As I can see, this is not true... When I PreviewMouseDown, then PreviewMouseUp, an PreviewMouseMove event interferes. Is this a bug in Framework or MSDN documentation leak?

I just need to differentiate when a element really moves, and this "static" "Move" breaks my logic...

Function calls log:

Function: MyCanvas.OnPreviewMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs), Thread: 0x6F4 Main Thread
Function: MyCanvas.OnPreviewMouseMove(System.Windows.Input.MouseEventArgs), Thread: 0x6F4 Main Thread
Function: MyCanvas.OnPreviewMouseLe开发者_开发百科ftButtonUp(System.Windows.Input.MouseButtonEventArgs), Thread: 0x6F4 Main Thread
Function: MyCanvas.OnPreviewMouseMove(System.Windows.Input.MouseEventArgs), Thread: 0x6F4 Main Thread

The previous log was obtained when obtaining also the DoubleClick event, so, I don't suppose I moved the mouse even by a micrometer...


Using simple handlers I was able to get PreviewMouseUp and PreviewMouseDown (and LeftButtonUp/Down) events to fire reliably without MouseMove interfering. I suspect that the behavior you're seeing is because, especially with modern high resolution mice, it's impossible to not move the mouse (even very slightly) while clicking it. Actually, it would be very foolish to assume your users won't do that. There's nothing preventing the user moving the mouse while keeping the mouse button pressed.

If you want to register the event sequence only if the mouse is stationary, record the position on mouse down and only do your actions on mouse up if the position changed significantly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜