microsoft/referencesource

Touches from dialog window get "stuck" in main window

Stannieman opened this issue · 2 comments

We are having quite a problem with our WPF app on touch devices. Sometimes after closing a modal window (opened with ShowDialog()) the buttons on our main window respond correctly to triggers on AreAnyTouchesOver, but they never fire a Click event or command when tapped. After quite some trail and error we believe we have found the issue causing this. The following scenario makes the issue appear.

Open a modal window and then make the UI thread busy for a while.
On the modal window there's a button that closes the window.
Now tap the close button and then any locations in the modal window (the close button or even some other place) WHILE the UI thread is still busy.
When the UI thread has done it's work it will see the click on the close button and close the window. All touches that came after the first tap on close appear now on the main window. However ONLY the (Preview)TouchDown events are raised in the main window and NO (Preview)TouchUp is ever occurring. This makes the main window think there are still fingers over itself while in reality they are not, and as a result when you tap a button this is seen as "1 more finger" instead of just a single finger tapping the screen.

So essentially the problem is that even after all threads are idle again our app is seeing fingers over itself while they are already long gone from the physical screen.

https://1drv.ms/u/s!AhqurxiexJWri5EleIA1-J6XZ0aKvA

This sample app is a minimal repro. After the dialog closes you can see that the PreviewTouchDown handler of the main window is fired the same number of times you tapped the dialog after you pressed close for the first time. The PreviewTouchUp handler is never fired. You can see that every time the PreviewTouchDown handler is fired a TouchDevice is added to the TouchesOver collection.

For some reason after a "random" amount of interactions with the app the number of devices decreases and from the moment all "ghost fingers" are gone the buttons work as expected again.

This is reproducible on Windows 10 1609 and up, but not on Windows 8.1.

We'll continue here: dotnet/wpf#450