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

时间:2019-03-26 00:42:15   收藏:0   阅读:243
原文:WPF 禁用TextBox的触摸后自动弹出虚拟键盘

前言 & 问题

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

技术分享图片

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

调用虚拟键盘

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

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

如何禁用键盘的弹出

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

处理方案:重写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

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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!