如何使 WPF 输入控件在触摸屏上获得焦点时显示虚拟键盘 [英] How to make WPF input control show virtual Keyboard when it got focus in touch screen

查看:206
本文介绍了如何使 WPF 输入控件在触摸屏上获得焦点时显示虚拟键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我们的 WPF 应用程序,当它在触摸屏(Surface Pro .etc)上运行时,TextBox/PasswordBox 控件无法显示<当他们专注时,强>虚拟键盘.

For our WPF application, when it runs on touch screen(Surface Pro .etc), the TextBox/PasswordBox control cannot show virtual keyboard when they get focused.

有什么好方法可以在 WPF 中实现此功能?

Any good way to implement this feature in WPF?

我们最终想要实现的是这样的:

what we want to achieve finally is something like that:

如果用户在PC上运行应用,我们不关心这个功能,也就是说用户是否有物理键盘,我们什么都不做,就像在PC上运行的普通WPF应用一样.

If user run app on PC, we don't care about this feature, which means whether user has physical keyboard, we do nothing just like normal WPF application running on PC.

如果用户在 Surface Pro 上运行,当他点击TextBox 时,可以显示内置的虚拟键盘,并且应该是用户友好的,例如键盘永远不会覆盖输入元素.

If user run on Surface Pro, when he clicks the TextBox, the built-in virtual keyboard can show up, and which should be user-friendly, such as the keyboard would never cover up the input element.

那么,WPF 无法轻松设置某些属性来实现此功能?在我看来,这个功能应该是WPF内置的,我不明白为什么找不到简单的方法来实现.

So, WPF cannot easily set some property to implement this feature? In my opinion, this feature should be built-in WPF, I don't understand why I cannot find an easy way to achieve.

推荐答案

试试这个,

首先检查是否存在物理键盘:

First check for a physical keyboard presence:

KeyboardCapabilities keyboardCapabilities = new Windows.Devices.Input.KeyboardCapabilities();
return  keyboardCapabilities.KeyboardPresent != 0 ? true : false;

如果找不到物理键盘,请使用windows内置的虚拟键盘:

If you do not find a physical keyboard, use the in-built virtual keyboard of windows:

Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) + Path.DirectorySeparatorChar + "osk.exe");

从这里得到帮助:链接 1链接 2

这篇关于如何使 WPF 输入控件在触摸屏上获得焦点时显示虚拟键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆