在Windows 8上以编程方式显示/隐藏键盘 [英] Show/Hide Keyboard programmatically on windows8

查看:95
本文介绍了在Windows 8上以编程方式显示/隐藏键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以编程方式在Windows Metro应用程序上显示/隐藏键盘.我最初以为我可以使用折叠的文本框并对其进行设置来做到这一点.但是,此链接中似乎不允许这样做.该链接还讨论了实现此目的的AutomationPeer和TextAutomationPeer.是否有关于如何使用这些资源的资源?

先谢谢了 PK

解决方案

来自此处,如果将输入控件设置为只读,则它将不会触发键盘,因此可以使用它来控制键盘何时打开.

在实现文本自动化对等方时,需要检查以下几件事:

  1. 确保您使用真实的触摸设备进行测试,或者使用带有基本触摸模式工具的模拟器进行测试.如果您不这样做,则自动对等项将不会被激活,因为它只能通过手写笔或触摸输入(不是鼠标)来激活.

  2. 确保您的自定义控件实现了OnCreateAutomationPeer这样的内容:

    受保护的重写AutomationPeer OnCreateAutomationPeer() { 返回新的CustomControl2AutomationPeer(this); }

  3. 确保自动化对等体实现FrameworkElementAutomationPeerITextProviderIValueProvider

在示例此处中找到更多详细信息. /p>

I am trying to show/hide keyboard on a Windows Metro app programmatically. I initially thought I could do it using a collapsed textbox and setting focus on it. But it seems like that has been disallowed in this link. The link also talks about the AutomationPeer and TextAutomationPeer to accomplish this. Is there a resource on how to use these ?

Thanks in advance PK

解决方案

From here:

UI Automation is the mechanism through which developers communicate whether or not a particular UI element can receive text input. You must ensure that the appropriate accessibility properties are set in your apps so that the touch keyboard will know to appear when focus lands on a specific UI element. For Windows-provided controls, this will be done automatically because proper accessibility properties are set by default, but for custom controls and experiences you must do additional work to set the accessibility properties correctly; remember that the touch keyboard reacts to these properties.

If you use C# or C++, use an AutomationPeer object, and specifically a TextAutomationPeer. A Windows 8 Release Preview sample will demonstrate how to do this in C#. Remember that the control must also be editable and able to receive text to get the keyboard to invoke, in addition to having the appropriate accessibility settings. Indicating that something can receive text when it cannot will mislead accessibility tools and the users who rely on them.

To enable user-driven invocation, we track the coordinates of the last touch event and compare them to the location of the bounding rectangle of the element that currently has focus. If the point is contained within the bounding rectangle, the touch keyboard is invoked.

So you cannot programmatically show the keyboard. The appropriate way to hide/show the keyboard is by setting your control to accept input using an AutomationPeer object.

From here, if you set the input control to read-only then it will not trigger the keyboard, so possibly you could use that to control when the keyboard opens.

Edit:

There are a few things to check when implementing the text automation peer:

  1. Make sure you either test with a real touch device or test using the simulator with the Basic Touch Mode tool. If you don't do this the automation peer won't activate since it is only activated by a stylus or a touch input (not mouse).

  2. Make sure your custom control implements OnCreateAutomationPeer something like this:

    protected override AutomationPeer OnCreateAutomationPeer() { return new CustomControl2AutomationPeer(this); }

  3. Make sure your Automation Peer implements FrameworkElementAutomationPeer, ITextProvider and IValueProvider

More details found in the example here.

这篇关于在Windows 8上以编程方式显示/隐藏键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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