WPF .NET app crashes, ComboBox and Menu events not fired on Tablets with Windows 10 Creators Update, .NET 4.7 or KB4034658

给你一囗甜甜゛ 提交于 2019-12-05 23:39:57

We have found a workaround but it also has some disadvantages. When disabling the RealTimeStylus at application startup, we cannot reproduce the issue anymore.

However, disabling the RealTimeStylus also disables ScrollViewer swiping using touch. It might also influence the usage of a stylus, I was not able to test this.

While this solution is not optimal, it might be sufficient for your case (or at least be a starting point).

    public static void DisableWPFTabletSupport()
    {
        // Get a collection of the tablet devices for this window.  
        TabletDeviceCollection devices = System.Windows.Input.Tablet.TabletDevices;

        if (devices.Count > 0)
        {
            // Get the Type of InputManager.
            Type inputManagerType = typeof(System.Windows.Input.InputManager);

            // Call the StylusLogic method on the InputManager.Current instance.
            object stylusLogic = inputManagerType.InvokeMember("StylusLogic",
                        BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                        null, InputManager.Current, null);

            if (stylusLogic != null)
            {
                //  Get the type of the device class.
                Type devicesType = devices.GetType();

                // Loop until there are no more devices to remove.
                int count = devices.Count + 1;

                while (devices.Count > 0)
                {
                    // Remove the first tablet device in the devices collection.
                    devicesType.InvokeMember("HandleTabletRemoved", BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.NonPublic, null, devices, new object[] { (uint)0 });

                    count--;

                    if (devices.Count != count)
                    {
                        throw new Win32Exception("Unable to remove real-time stylus support.");
                    }
                }
            }
        }
    }

this question is a bit back, but I have an explanation for the "no longer responding to the GUI".

If an item is not 100% visible in the listview (deposited) and you execute a click, then the listview scrolls the item fully visible first. Everything works with the mouse. But the TouchUp event fires just before scrolling. And that's exactly where the mistake happens. I bypass this by waiting for the "Click-Event", no matter if touch or mouse, 10ms and only then execute my action. Thus, the error is fixed with me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!