简体   繁体   中英

Touch events not firing C# WPF

I have created a program that subscribes to WPF's touch events. Everything has been working as expected over the last few months, but yesterday none of the touch events would fire. I tried creating a new, simple program to test touch events, but it works the same, all of the touch input gets sent as mouse events, even though the cursor changes from the mouse arrow to the touch crosshairs.

I restarted the computer several times and reinstalled the drivers but it did not seem to change anything. I have tried using a different brand of touch screen with different drives which also used to work and am seeing the exact same issue. Using the touch screen's built in test tool, I can see that touch and multitouch are working as I expect and viewing the Pen and Touch section of the System Properties confirms that the computer is recognizing the touch screen.

EDIT: I continued to test the monitor and it appears that multitouch is working in other windows programs like paint. The touch appears to not work only in my applications.

Has anyone else experienced this or have any idea how to re-enable the touch events?

It does not sound like a driver issue. May be in one of your touch down events you are releasing the TouchCapture . You need to check your code. Search for .ReleaseTouchCapture(e.TouchDevice); and check whether you are using this in the right place.

A bit late for an answer to this specific question but since I had a similar problem and it took me a while to find a solution here is what I came up with. In WPF the click event on Buttons disables touch input. A simple workaround is this new class:

public class TouchButton : Button
{
    public TouchButton()
    {
        TouchDown += TouchButton_TouchDown;
    }

    private void TouchButton_TouchDown(object sender, System.Windows.Input.TouchEventArgs e)
    {
        RaiseEvent(new RoutedEventArgs(ClickEvent));
    }
}

If you change the buttons in your Xaml to TouchButtons, the click will automatically be triggered by a touch(down). It is pretty straightforward and can easily be adapted to all kinds of situations.

Somehow, converting the Window to a UserControl and hosting inside a WinForms Window fixed the problem and touch events fire as they did before.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM