首页 > Windows开发 > 详细

WPF 禁用TextBox的触摸后自动弹出虚拟键盘

时间:2018-12-21 23:41:46      阅读:229      评论:0      收藏:0      [点我收藏+]
原文:WPF 禁用TextBox的触摸后自动弹出虚拟键盘

前言 & 问题

如下截图,TextBox,在触摸点击后,会自动弹出windows的虚拟键盘。

技术分享图片

如何,禁用键盘的自动弹出?

调用虚拟键盘

通过调用TapTip.exe或者osk.exe,主动弹出虚拟键盘

详细调用可参考:c#调用windows虚拟键盘

如何禁用键盘的弹出

TextBox在触摸点击后,会自动弹出虚拟键盘,是因为在控件中作了封装。

--TextBox中详细TabTip.exe封装看了会,没找到

处理方案:重写TextBox的方法OnCreateAutomationPeer,返回一个UIElementAutomationPeer而不是AutomationPeer。

可能原因:TextBox自定义实现中返回的是AutomationPeer,而UIElementAutomationPeer继承AutomationPeer,重写了相关键盘属性。

猜测与HasKeyboardFocusCore属性有关。

技术分享图片

直接复制如下代码:

 1     /// <summary>
 2     /// 禁用自动弹出虚拟键盘的TextBox控件
 3     /// </summary>
 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

WPF 禁用TextBox的触摸后自动弹出虚拟键盘

原文:https://www.cnblogs.com/lonelyxmas/p/10159254.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!