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

thi*_*ick 15 c# user-interface microsoft-metro 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);
        }


    }

    protected override AutomationPeer OnCreateAutomationPeer()
    {
        var baseItem = base.OnCreateAutomationPeer();
        return new KeyboardUnfocusableGridViewAutomationPeer(this);
    }

    protected override Windows.UI.Xaml.DependencyObject GetContainerForItemOverride()
    {
        return new KeyboardUnfocusableGridViewItem();
    }
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,我需要编写这么多代码来做一件简单的事情.这绝对不是最佳的,因为我需要为ItemsControl我需要使用的每一个做这个.

Jar*_*SFT 3

您需要做的是将焦点设置到任何不接受文本输入的控件。但是,请注意,如果用户手动显示键盘(而不是因为文本框接收到焦点而自动显示),则键盘将保持打开状态。

查看这个关于屏幕键盘的非常好的线程以获取更多信息:

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