触摸WPF按钮有时不会在Windows 8下调用点击处理程序 [英] Touching a WPF button does sometimes not invoke the click handler under Windows 8

查看:47
本文介绍了触摸WPF按钮有时不会在Windows 8下调用点击处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当应用程序窗口没有焦点时,有时不会在按钮触摸时调用单击处理程序."

"When the application window does NOT have the focus, sometimes the click handler is not called on button-touch."

系统:

带有多点触控输入设备的Windows 8.1.

Windows 8.1 with a multi-touch input device.

软件:

一个简单的WPF 4.5.2应用程序,其中只有一个按钮,用于记录是否调用了单击处理程序(只需创建一个新项目,并将带有单击处理程序的按钮添加到MainWindow中).

A simple WPF 4.5.2 application with just one button that logs if the click handler is called (just create a new project and add a button with a click handler to the MainWindow).

现象:

通常在触摸按钮时会调用其单击处理程序. 但是当应用程序窗口没有焦点时,有时单击按钮时就不会调用单击处理程序 (尽管按钮的颜色变为蓝色).当应用程序窗口已经成为焦点时,触摸按钮始终有效.这仅在某些情况下会发生,但会在具有不同触摸硬件的所有系统上发生(所有Windows 8.1).我从未在Windows 7上体验过它.使用鼠标,无论窗口是否聚焦,它都可以工作.

Normally when touching the button its click handler is called. But when the application window does NOT have the focus, sometimes the click handler is not called on button-touch (although the button color changes to blue). When the application window has already the focus, touching the button works all the time. This happens only sometimes but occurs on various systems with different touch hardware (all windows 8.1). I never experienced it on windows 7. With the mouse it works regardless if the window is focused or not.

(发生在发布和调试模式下,带有或不带有调试器)

(Happens in release and debug mode, with and without debugger attached)

测试:

我检查了Windows中的各种触摸设置并进行了播放.我还重新校准了触摸->没有区别.

I checked the various touch settings in windows and played with it. I also re-calibrating the touch -> no difference.

在检查WPF按钮的鼠标和触摸事件时,如果发生错误,最后收到的事件是PreviewMouseUp,但没有单击!

When checking the WPF button mouse and touch events, then in the error case the last received event is PreviewMouseUp but no Click!

当我查看收到的窗口消息(spy ++)时,会得到以下内容(为了更好地了解,删除了WM_IME_SETCONTEXT,WM_GETTEXT,WM_NCHITTEST,WM_GETOBJECT):

When I look at the received window messages (spy++) I get the following (WM_IME_SETCONTEXT, WM_GETTEXT, WM_NCHITTEST, WM_GETOBJECT removed for a better overview):

已收到点击:

Click was received:

R WM_POINTERACTIVATE pmsd->lResult:FFFFFFFFFFFFFFFF
S WM_MOUSEACTIVATE hwndTopLevel:000503F8 nHittest:HTCLIENT uMsg:WM_POINTERDOWN
R WM_MOUSEACTIVATE fuActivate:MA_ACTIVATE
S WM_WINDOWPOSCHANGING lpwp:000000E9E3D9E410
R WM_WINDOWPOSCHANGING
S WM_WINDOWPOSCHANGED lpwp:000000E9E3D9E410
R WM_WINDOWPOSCHANGED
S WM_ACTIVATEAPP fActive:True dwThreadID:00000000
R WM_ACTIVATEAPP
S WM_NCACTIVATE fActive:True
R WM_NCACTIVATE
S WM_ACTIVATE fActive:WA_ACTIVE fMinimized:False hwndPrevious:(null)
S WM_IME_NOTIFY dwCommand:IMN_OPENSTATUSWINDOW dwCommand:00000002 dwData:00000000
R WM_IME_NOTIFY
S WM_SETFOCUS hwndLoseFocus:(null)
R WM_SETFOCUS
R WM_ACTIVATE
S message:0x02CC [Unknown] wParam:00000000 lParam:00C50BA8
R message:0x02CC [Unknown] lResult:00000100
P WM_POINTERENTER wPointerID:0099 wFlags:6017
S WM_SETCURSOR hwnd:000503F8 nHittest:HTCLIENT wMouseMsg:WM_LBUTTONDOWN
R WM_SETCURSOR fHaltProcessing:False
P WM_LBUTTONDOWN fwKeys:MK_LBUTTON xPos:145 yPos:62
R WM_POINTERCAPTURECHANGED
P WM_MOUSEMOVE fwKeys:MK_LBUTTON xPos:145 yPos:62
P WM_POINTERLEAVE wPointerID:0099 wFlags:6000
P WM_LBUTTONUP fwKeys:0000 xPos:145 yPos:62
P WM_MOUSEMOVE fwKeys:0000 xPos:145 yPos:62
S WM_CAPTURECHANGED hwndNewCapture:000503F8
R WM_CAPTURECHANGED
S WM_CAPTURECHANGED hwndNewCapture:00000000
R WM_CAPTURECHANGED
S WM_SETCURSOR hwnd:000503F8 nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
R WM_SETCURSOR fHaltProcessing:False
P WM_MOUSEMOVE fwKeys:0000 xPos:145 yPos:62

点击未收到

Click NOT received

S message:0x02CC [Unknown] wParam:00000000 lParam:00AE0BA9
R message:0x02CC [Unknown] lResult:00000100
R WM_POINTERACTIVATE pmsd->lResult:FFFFFFFFFFFFFFFF
S WM_MOUSEACTIVATE hwndTopLevel:000503F8 nHittest:HTCLIENT uMsg:WM_POINTERDOWN
R WM_MOUSEACTIVATE fuActivate:MA_ACTIVATE
S WM_WINDOWPOSCHANGING lpwp:000000E9E3D9E410
R WM_WINDOWPOSCHANGING
S WM_WINDOWPOSCHANGED lpwp:000000E9E3D9E410
R WM_WINDOWPOSCHANGED
S WM_ACTIVATEAPP fActive:True dwThreadID:00000000
R WM_ACTIVATEAPP
S WM_NCACTIVATE fActive:True
R WM_NCACTIVATE
S WM_ACTIVATE fActive:WA_ACTIVE fMinimized:False hwndPrevious:(null)
S WM_IME_NOTIFY dwCommand:IMN_OPENSTATUSWINDOW dwCommand:00000002 dwData:00000000
R WM_IME_NOTIFY
S WM_SETFOCUS hwndLoseFocus:(null)
R WM_SETFOCUS
R WM_ACTIVATE
P WM_POINTERENTER wPointerID:0090 wFlags:6017
S WM_SETCURSOR hwnd:000503F8 nHittest:HTCLIENT wMouseMsg:WM_LBUTTONDOWN
R WM_SETCURSOR fHaltProcessing:False
P WM_LBUTTONDOWN fwKeys:MK_LBUTTON xPos:147 yPos:39
R WM_POINTERCAPTURECHANGED
S WM_SETCURSOR hwnd:000503F8 nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
R WM_SETCURSOR fHaltProcessing:False
P WM_MOUSEMOVE fwKeys:MK_LBUTTON xPos:147 yPos:39
P WM_POINTERLEAVE wPointerID:0090 wFlags:6000
S WM_SETCURSOR hwnd:000503F8 nHittest:HTCLIENT wMouseMsg:WM_LBUTTONUP
R WM_SETCURSOR fHaltProcessing:False
P WM_LBUTTONUP fwKeys:0000 xPos:147 yPos:39
S WM_SETCURSOR hwnd:000503F8 nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
R WM_SETCURSOR fHaltProcessing:False
P WM_MOUSEMOVE fwKeys:0000 xPos:147 yPos:39
S WM_SETCURSOR hwnd:000503F8 nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
R WM_SETCURSOR fHaltProcessing:False
P WM_MOUSEMOVE fwKeys:0000 xPos:147 yPos:39
S WM_SETCURSOR hwnd:000503F8 nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
R WM_SETCURSOR fHaltProcessing:False
P WM_MOUSEMOVE fwKeys:0000 xPos:147 yPos:39

在错误中还有其他行

S WM_SETCURSOR hwnd:000503F8 nHittest:HTCLIENT wMouseMsg:WM_LBUTTONUP
R WM_SETCURSOR fHaltProcessing:False

在WM_LBUTTONUP之前.但是我不知道这是否重要.

before WM_LBUTTONUP. But I don't know if this matter.

我已经尝试调试.net代码,以查看导致不调用Click处理程序的情况,但是我很快迷失在System.Windows.Input.InputManager和System.Windows.Input的PromoteMainToMouse()函数中.StylusLogic.

I already tried to debug the .net code to see which condition causes to not call the Click handler but I soon got lost in the System.Windows.Input.InputManager and the PromoteMainToMouse() function of System.Windows.Input.StylusLogic.

我真的没什么要检查的主意了.因此,如果有人可以给我建议,还可以测试什么,或者在.net中设置断点的位置找到根本原因,那将是很好的.甚至更好地找到解决方案/解决方法.

I'm really running out of ideas what to check. So it would be great if someone could give me advice what else to test or where to set breakpoints in .net to find the root-cause. Or even better find a solution/workaround.

更新:

我发现,即使只是将鼠标指针从应用程序窗口移开(至少在我们的平台上),我也可以重现这种现象.而且,发生错误的可能性似乎随着用户界面的复杂性而增加–我的测试应用程序并非总是无法识别点击,而是每次都会导致复杂的WPF应用程序失败.

I found out that I can reproduced the phenomenon also if the mouse pointer is just moved away from the application window (at least on our platforms). And the probability for the bug to occur seems to increase with the complexity of the user interface – my test app not always fails to recognize the click but a complex WPF app fails each time.

您应该可以在Windows 8.1上使用触摸设备在WPF开发人员工作室(例如2013版)中复制它:

You should be able to reproduce it with the WPF developer studio (e.g. version 2013) on Windows 8.1 with a touch device:

  • 打开开发人员工作室以仅覆盖触摸屏的一半
  • 移开移动,使光标指向桌面区域
  • 触摸按钮(例如开始调试" –播放按钮):在我的情况下,第一次触摸永远不会导致点击事件.

推荐答案

事实证明这是WPF中的一个BUG.在发布KB之前,有一种解决方法.

It has turned out to be a BUG in WPF. There is a workaround available until a KB is released.

解决方法是在受影响的MainWindow的UIElement的 PreviewTouchDown 事件处理程序中调用 Mouse.Synchronize(); .

The workaround is to call Mouse.Synchronize(); in the PreviewTouchDown event handler of the affected UIElement of MainWindow.

我对其进行了测试,并且效果很好.

I tested it and it works fine.

这篇关于触摸WPF按钮有时不会在Windows 8下调用点击处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆