zoukankan      html  css  js  c++  java
  • WPF 平板上按钮点击不触发,鼠标点击触发的两种解决方法

    今天运行在windows平板上的程序,有个功能是弹出子窗体,点弹出窗体的关闭按钮,要点好几次才能触发。网上找了找,也有人与我类似的情形。

    解决方法如下:

    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.");
                            }
                        }
                    }
                }
            }

    这种方式,是禁用掉wpf对平板功能的支持,我试了下,确实点击关闭按钮很容易触发。但是这个方法会把滑动效果禁掉。比如滑动列表。这样用户体验会不好。

    后来想了想,触摸屏点击肯定会触发TouchDown事件的。

       private void Button_TouchDown(object sender, TouchEventArgs e)
            {
                this.Close();
            }

    很简单就解决了。

  • 相关阅读:
    HTTP 协议中的并发限制及队首阻塞问题
    聊聊JMM
    聊聊CacheLine
    git解决本地建立git仓库 连接远程git仓库出现拒绝合并问题
    django 本地项目部署uwsgi 以及云服务器部署 uwsgi+Nginx+Docker+MySQL主从
    我的第一篇播客
    大爷的超市管理系统——冲刺第一天
    能混绝不C——凡事预则立
    2020软件工程团队作业——05
    2020软件工程作业——04
  • 原文地址:https://www.cnblogs.com/czly/p/10222528.html
Copyright © 2011-2022 走看看