内容简介:您需要做的是将焦点设置为不接受文本输入的任何控件.但是,请注意,如果用户手动显示键盘(而不是由于TextBox接收到焦点而自动显示),则键盘将保持打开状态.查看这个关于屏幕键盘的很好的线索了解更多信息:
我在C#中开发我的Windows 8应用程序,一个非常令人讨厌的事情是,即使所有的文本框都失去了焦点,触摸键盘有时会保持在屏幕上.
我阅读了文章 keyboard dismissal logic white paper ,这解释说,当从控制切换到控制时,键盘可以保持打开,即使控件可能不接受键盘输入.这将是我的情况,因为我的所有内容都托管在GridView或ListView中.当用户点击屏幕上的任何项目时,水龙头将落在这些控件上.这是非常烦人的,因为键盘需要一半的屏幕,没有办法关闭键盘.
我试图将文本框设置为禁用并且没有影响.删除键盘的唯一方法是设置焦点在一个按钮,这是非常黑客.
我以为我需要用“AutomationPeer”做一些事情,但我不清楚究竟要做什么.有没有办法来重写这个行为?
编辑:
我想出了这一点.目标是更改为 whitepaper 中未列出的GridView和GridView项目的控件类型.以下是我所做的允许我关闭键盘的网格代码:
public class KeyboardUnfocusableGridView : GridView
{
private class KeyboardUnfocusableGridViewAutomationPeer : GridViewAutomationPeer
{
public KeyboardUnfocusableGridViewAutomationPeer(GridView owner)
: base(owner)
{
}
protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.Custom;
}
}
private class KeyboardUnfocusableGridViewItemAutomationPeer : GridViewItemAutomationPeer
{
public KeyboardUnfocusableGridViewItemAutomationPeer(GridViewItem owner)
: base(owner)
{ }
protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.Custom;
}
}
private class KeyboardUnfocusableGridViewItem : GridViewItem
{
protected override AutomationPeer OnCreateAutomationPeer()
{
var baseItem = base.OnCreateAutomationPeer();
return new KeyboardUnfocusableGridViewItemAutomationPeer(this);
}
}
protected override AutomationPeer OnCreateAutomationPeer()
{
var baseItem = base.OnCreateAutomationPeer();
return new KeyboardUnfocusableGridViewAutomationPeer(this);
}
protected override Windows.UI.Xaml.DependencyObject GetContainerForItemOverride()
{
return new KeyboardUnfocusableGridViewItem();
}
}
不幸的是,我需要写这么多代码来做一个简单的事情.这绝对不是最佳的,因为我需要为我需要使用的每个ItemsControl这样做.
您需要做的是将焦点设置为不接受文本输入的任何控件.但是,请注意,如果用户手动显示键盘(而不是由于TextBox接收到焦点而自动显示),则键盘将保持打开状态.
查看这个关于屏幕键盘的很好的线索了解更多信息:
http://stackoverflow.com/questions/12149006/windows-8-how-to-dismiss-touch-keyboard
以上所述就是小编给大家介绍的《c# – Windows 8 – 如何关闭触摸键盘?》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- 微软比谷歌还积极,努力优化Windows 10 Chrome浏览器触摸键盘
- 通过解读 WPF 触摸源码,分析 WPF 插拔设备触摸失效的问题(问题篇)
- WPF 触摸到事件
- Android触摸事件传递机制
- 【透镜系列】看穿 > 触摸事件分发
- iOS —— 触摸事件传递及响应与手势
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Fluent Python
Luciano Ramalho / O'Reilly Media / 2015-8-20 / USD 39.99
Learn how to write idiomatic, effective Python code by leveraging its best features. Python's simplicity quickly lets you become productive with it, but this often means you aren’t using everything th......一起来看看 《Fluent Python》 这本书的介绍吧!
HTML 编码/解码
HTML 编码/解码
RGB CMYK 转换工具
RGB CMYK 互转工具