Windows 8的 - 如何辞退触感键盘? [英] Windows 8 - How to Dismiss Touch Keyboard?

查看:94
本文介绍了Windows 8的 - 如何辞退触感键盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发我的Windows 8应用在C#中,还有一个很烦人的事情是,触摸式键盘,有时停留在即使所有的文本框已经失去焦点屏幕。

I am developing my app for Windows 8 in C#, and one very annoying thing is that the touch keyboard sometimes stays on screen even though all textboxes have lost focus.

我读了文章键盘解雇逻辑白皮书,该解释说,从控制到控制切换时,键盘可以留在即使控制可能不接受键盘输入。因为我所有的内容在任何一个GridView或一个ListView托管这将是我的情况。当用户点击屏幕上的任何项目,自来水将降落在这些控制。这是很烦人的,因为键盘需要的画面的一半,也没有办法来关闭键盘。

I read the article keyboard dismissal logic white paper, which explains that when switching from control to control, the keyboard can stay on even though a control may not accept keyboard input. This would be my case because all my contents are hosted in either a GridView or a ListView. When the user clicks on any item on screen, the tap would land on these controls. This is very annoying because the keyboard takes half of a screen and there is no way to close the keyboard.

我试图设置文本框被禁用并且它有没有影响。拆下键盘的唯一方法是将焦点设置一个按钮,这是非常哈克。

I have tried to set the textbox to be disabled and it had not affect. The only way to remove the keyboard is to set focus on a button, which is extremely hacky.

我想我需要做的的AutomationPeer的东西,但我我不清楚究竟是什么做的。 ?有没有一种方法可以覆盖这种行为

I thought I needed to do something with the "AutomationPeer", but I am not clear what exactly to do. Is there a way to override this behavior?

编辑:
我想通了这一点。我们的目标是改变在的白皮书。下面是我,让我取消键盘网格的代码:

I figured this out. The goal is to change to the control type of the GridView and GridView item not listed in the whitepaper. Here is the code of the grid that I did that allowed me to dismiss the keyboard:

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 ,我需要使用。

推荐答案

您需要做的是将焦点设置到不接受文本输入任何控制什么。但是,请注意,如果用户手动显示键盘(相对于它会自动显示,因为一个文本框获得焦点),那么键盘将继续开放。

What you need to do is set focus to any control that does not accept text entry. However, be aware that if the user manually showed the keyboard (as opposed to it automatically showing because a TextBox received focus) then the keyboard will remain open.

看看这个有关屏幕键盘的更多信息真的好螺纹:

Check out this really good thread about the on-screen keyboard for more info:

http://social.msdn.microsoft.com/Forums/pl/winappswithcsharp/thread/3c227262-1d2c-4382-9c50-5b71d2b5d823

这篇关于Windows 8的 - 如何辞退触感键盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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