前言
最近一段时间在做关于WPF开发的应用程序在平板上运行的相关开发,期间踩了无数坑总算满足了应用程序完美第一宗旨——客户满意!!!!接下来总结了一下相关技术要点:
提示:以下是本篇文章正文内容,下面案例可供参考
一、禁用 WPF 平板电脑支持
WPF内置了对处理 Windows 触摸输入的支持。该支持来自平板电脑平台的实时手写笔输入,如OnStylusDown、OnStylusUp和OnStylusMove事件。Windows 7 还提供多点触控输入作为 Win32 WM_TOUCH 窗口消息。这两个 API 在同一个 HWND 上是互斥的。通过平板电脑平台启用触摸输入(WPF 应用程序的默认设置)会禁用 WM_TOUCH 消息。因此,要使用 WM_TOUCH 从 WPF 窗口接收触摸消息,您必须禁用 WPF 中的内置手写笔支持。这适用于承载使用 WM_TOUCH 的组件的 WPF 窗口等场景。
要禁用 WPF 侦听手写笔输入,就得删除 WPF 窗口添加的任何数位板支持。
public static void DisableWPFTabletSupport()
{
TabletDeviceCollection devices = System.Windows.Input.Tablet.TabletDevices;
if (devices.Count > 0)
{
Type inputManagerType = typeof(System.Windows.Input.InputManager);
object stylusLogic = inputManagerType.InvokeMember("StylusLogic",
BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
null, InputManager.Current, null);
if (stylusLogic != null)
{
Type devicesType = devices.GetType();
int count = devices.Count + 1;
while (devices.Count > 0)
{
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.");
}
}
}
}
}
二、防止滑动条造成的软件被惯性拖动
ManipulationBoundaryFeedback 事件使应用程序或组件能够在对象碰到边界时提供视觉反馈。例如,Window 类处理 ManipulationBoundaryFeedback 事件,使窗口在遇到其边缘时稍微移动。
/// <summary>
/// 防止惯性拖动
/// </summary>
/// <param name="e"></param>
protected override void OnManipulationBoundaryFeedback(System.Windows.Input.ManipulationBoundaryFeedbackEventArgs e)
{
e.Handled = true;
base.OnManipulationBoundaryFeedback(e);
}
总结
例如:以上就是今天要讲的内容,本文仅仅简单介绍了部分WPF对平板触摸操作的支持总结,有些问题还是得自己在实际开发过程中去踩坑去解决。