wpf 是否可以在 c# 中显示、隐藏和操作 Windows 8 屏幕键盘?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14571065/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible in c# to show, hide, and manipulate the Windows 8 on-screen keyboard?
提问by David
I am making a WPF application that is to be used on a kiosk with no hardware keyboard. Currently we are using a third party on-screen keyboard, but the Windows 8 version is a lot better and we are thinking of switching to it.
我正在制作一个 WPF 应用程序,该应用程序将在没有硬件键盘的信息亭上使用。目前我们使用的是第三方屏幕键盘,但 Windows 8 版本要好得多,我们正在考虑改用它。
So my question is simply if it is possible to show/hide it as well as show a numeric only version using c#.
所以我的问题很简单,是否可以显示/隐藏它以及使用 c# 显示仅数字版本。
Thanks! David
谢谢!大卫
采纳答案by Jennifer Marsman - MSFT
From this source:
从这个来源:
There is no direct way to control the touch keyboard programmatically. Requiring the user to set the focus rather than the program is a deliberate design decision to prevent UI churn.
See Input Hosting Manager and the Touch Keyboardfor more information on how and why this works. The User-driven invocationsection of that document explains the specific behavior you are asking about.
没有直接的方法来以编程方式控制触摸键盘。要求用户设置焦点而不是程序是一个深思熟虑的设计决策,以防止 UI 流失。
请参阅输入托管管理器和触摸键盘,了解有关其工作原理和原因的更多信息。该文档的用户驱动调用部分解释了您所询问的特定行为。
But, once the user touches an input control, the soft keyboard will automatically be displayed (with no extra coding needed).
但是,一旦用户触摸输入控件,软键盘将自动显示(无需额外编码)。
Finally, to address your question on a numeric-only version of a keyboard, you may propose a different keyboard layout using InputScopeon a TextBox. The different input scopes are enumerated here, but one of them is "Number".
最后,要解决有关纯数字版本键盘的问题,您可以在 TextBox 上使用InputScope建议不同的键盘布局。这里列举了不同的输入范围,但其中之一是“数字”。
回答by Dmitry Lyalin
I've published a sample on how to trigger the touch keyboard in WPF applications when a user clicks into a Textbox, its here:
我已经发布了一个关于如何在用户单击文本框时触发 WPF 应用程序中的触摸键盘的示例,它在这里:
http://code.msdn.microsoft.com/Enabling-Windows-8-Touch-7fb4e6de
http://code.msdn.microsoft.com/Enabling-Windows-8-Touch-7fb4e6de
I've been working on this sample for many months and am glad to finally contribute it to our community. Please let me know if there are any questions, suggestions, problems, etc in the sample Q&A pane
我已经研究这个样本好几个月了,很高兴终于将它贡献给我们的社区。如果示例问答窗格中有任何问题、建议、问题等,请告诉我
Also note that while demonstrate how to "show" the keyboard, i'm not sure how to dismiss it programmatically at this point so its important to test any actual implementation to ensure its a good experience. For example some controls like Button will dismiss the keyboard when they get focus from a TextBox, but certain ones like Checkbox will not and I demonstrate that in my sample.
另请注意,虽然演示如何“显示”键盘,但我不确定此时如何以编程方式关闭它,因此测试任何实际实现以确保其良好体验很重要。例如,像 Button 这样的一些控件在从 TextBox 获得焦点时会关闭键盘,但某些像 Checkbox 这样的控件不会,我在我的示例中演示了这一点。

