相关疑难解决方法(0)

Windows 8 - 如何解除触摸键盘?

我正在用C#开发我的Windows 8应用程序,一个非常令人讨厌的事情是触摸键盘有时会停留在屏幕上,即使所有文本框都失去焦点.

我阅读了文章键盘解雇逻辑白皮书,它解释了当从控制切换到控制时,即使控件可能不接受键盘输入,键盘也可以保持打开状态.这将是我的情况,因为我的所有内容都托管在GridView或ListView中.当用户点击屏幕上的任何项目时,点击将落在这些控件上.这非常烦人,因为键盘需要一半的屏幕,而且无法关闭键盘.

我试图将文本框设置为禁用,但它没有影响.删除键盘的唯一方法是将焦点设置在按钮上,这非常黑客.

我认为我需要对"AutomationPeer"做些什么,但我不清楚究竟要做什么.有没有办法覆盖这种行为?

编辑: 我想出来了.目标是更改为白皮书中未列出的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);
        } …
Run Code Online (Sandbox Code Playgroud)

c# user-interface microsoft-metro windows-8

15
推荐指数
1
解决办法
7782
查看次数

焦点更改后,键盘也不会消失

我正在创建一个Windows 8.1应用程序,在用户按下按钮后,弹出窗口将打开大部分屏幕.popover中有几个文本框.

我从microsoft 找到了这个示例代码,介绍了如何检测屏幕键盘的外观.

我还发现以下SO帖子和网站基本上告知没有办法强制键盘关闭,而正确的做法实际上是以编程方式将隐藏元素集中在页面上或禁用然后重新启用文本框:

所以我按照建议创建了一个隐形按钮.当用户点击关闭按钮时,它应该关注该按钮并关闭键盘.什么情况是文本框确实失去焦点,但键盘不会消失.如果我使关闭按钮将焦点置于隐藏按钮关闭弹出窗口(这是所需的效果),则在点击视图(之前在弹出窗口下)之前键盘不会消失.

如何关闭弹出窗口导致键盘解除?

编辑:似乎有一种方法可以以编程方式关闭键盘,因为在键盘打开时触发App Bar打开会自动关闭键盘.

c# windows xaml

7
推荐指数
1
解决办法
5845
查看次数

如何在EditText软键盘上隐藏8个Metro应用程序?

我在使用C#的框架中有一个EditText和一个Button.在编辑字段内写入并单击按钮后,我想隐藏虚拟软键盘.

c# xaml windows-8 windows-runtime winrt-xaml

1
推荐指数
1
解决办法
7942
查看次数