WPF 禁用TextBox的触摸后自动弹出虚拟键盘 | 您所在的位置:网站首页 › win10触摸屏虚拟键盘不弹出界面 › WPF 禁用TextBox的触摸后自动弹出虚拟键盘 |
原文:
WPF 禁用TextBox的触摸后自动弹出虚拟键盘
前言 & 问题
如下截图,TextBox,在触摸点击后,会自动弹出windows的虚拟键盘。 如何,禁用键盘的自动弹出? 调用虚拟键盘通过调用TapTip.exe或者osk.exe,主动弹出虚拟键盘 详细调用可参考:c#调用windows虚拟键盘 如何禁用键盘的弹出TextBox在触摸点击后,会自动弹出虚拟键盘,是因为在控件中作了封装。 --TextBox中详细TabTip.exe封装看了会,没找到 处理方案:重写TextBox的方法OnCreateAutomationPeer,返回一个UIElementAutomationPeer而不是AutomationPeer。 可能原因:TextBox自定义实现中返回的是AutomationPeer,而UIElementAutomationPeer继承AutomationPeer,重写了相关键盘属性。 猜测与HasKeyboardFocusCore属性有关。 直接复制如下代码: 1 /// 2 /// 禁用自动弹出虚拟键盘的TextBox控件 3 /// 4 public class TextBoxNoAutoKeyboard : TextBox 5 { 6 protected override AutomationPeer OnCreateAutomationPeer() 7 { 8 return new FrameworkElementAutomationPeer(this); 9 } 10 }以上参考自:【stackoverflow】“Hide” text box from automatic Win10 keyboard showing |
CopyRight 2018-2019 实验室设备网 版权所有 |