WPF 获得触摸精度和触摸点

原文:
WPF 获得触摸精度和触摸点

本文主要告诉大家如何获得所有的触摸设备的触摸精度和触摸点数。

需要通过反射的方法才可以拿到触摸的精度。

使用 Tablet.TabletDevices 可以获得所有的触摸设备,获得触摸点数可以通过下面代码

foreach (TabletDevice device in Tablet.TabletDevices){ Console.WriteLine("触摸点数" + device.StylusDevices.Count);//触摸点数}

触摸精度就需要使用反射

 var builder = new StringBuilder(); foreach (TabletDevice device in Tablet.TabletDevices) { var deviceProperty = typeof(TabletDevice).GetProperty("TabletDeviceImpl", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty); var deviceImpl = deviceProperty is null ? device : deviceProperty.GetValue(device); var info = deviceImpl.GetType().GetProperty("TabletSize", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty); var tabletSize = (Size) info.GetValue(deviceImpl, null); if (device.Type == TabletDeviceType.Touch) { builder.Append(string.Format("{1}:{2} 点触摸,精度 {3}{0}", Environment.NewLine, device.Name, device.StylusDevices.Count, tabletSize)); } else { builder.Append(string.Format("{1}:{2} 个触笔设备,精度 {3}{0}", Environment.NewLine, device.Name, device.StylusDevices.Count, tabletSize)); } }

如果发现设备触摸失效,可以使用这个项目

ManipulationDemo


本文会经常更新,请阅读原文: https://lindexi.gitee.io/lindexi/post/WPF-%E8%8E%B7%E5%BE%97%E8%A7%A6%E6%91%B8%E7%B2%BE%E5%BA%A6%E5%92%8C%E8%A7%A6%E6%91%B8%E7%82%B9.html ,以避免陈旧错误知识的误导,同时有更好的阅读体验。

WPF 获得触摸精度和触摸点 本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。欢迎转载、使用、重新发布,但务必保留文章署名林德熙(包含链接: https://lindexi.gitee.io ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请 与我联系

相关文章