Skip to content

Touches from dialog window get "stuck" in main window #450

Open

Description

I asked this question already in the other forums but still haven't been able to get a solution for it or even have somebody looking at it, so I'll try it again here (this is copy paste from other post here):


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.

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.

We did not yet find a solution to resolve this issue.

We tried looping over PeekMessage (from User32.dll) to remove all touches in the queue but both WM_TOUCH and WM_GESTURE don't appear in there, even after calling RegisterTouchWindow. PeekMessage works fine for mouse though but we don't have mouse problems.

We also tried putting an in-between-window between the main window and our modal dialog. This works in the sense that we see the rogue touches coming to the in-between-window, and after we close it the main window will have 0 TouchesOver. But still this does not resolve the issue. We even tried using reflection in the in-between-window to call ReportUp and Deactivate on every TouchDevice in TouchesOver of the in-between-window. And we can see that it has an effect because they are 1 by 1 removed from TouchesOver. But even then after the in-between-window closes and with 0 TouchesOver on any window our main window does not correctly handle touch.

I did find something very suspicious in the .NET source code: https://referencesource.microsoft.com/#PresentationCore/Core/CSharp/System/Windows/Input/TouchDevice.cs,720


So... if anyone has a robust solution this would be very welcome. If not we have to revert to set IsChecked, raise Click event, run Commands, etc all manually in global TouchUp handlers for all buttons.

Regards,
Stan

This issue has been moved from https://developercommunity.visualstudio.com/content/problem/496835/touches-from-dialog-window-get-stuck-in-main-windo.html
VSTS ticketId: 822709

These are the original issue comments:
(no comments)
These are the original issue solutions:
(no solutions)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    BugProduct bug (most likely)

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions