c# – Windows 8 – 如何关闭触摸键盘?

栏目: ASP.NET · 发布时间: 5年前

内容简介:您需要做的是将焦点设置为不接受文本输入的任何控件.但是,请注意,如果用户手动显示键盘(而不是由于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://social.msdn.microsoft.com/Forums/pl/winappswithcsharp/thread/3c227262-1d2c-4382-9c50-5b71d2b5d823

http://stackoverflow.com/questions/12149006/windows-8-how-to-dismiss-touch-keyboard


以上所述就是小编给大家介绍的《c# – Windows 8 – 如何关闭触摸键盘?》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Sexy Web Design

Sexy Web Design

Elliot Stocks / SitePoint / 2009-03-28 / $39.95

Description A guide to building usable, aesthetically pleasing interfaces for web sites and web applications by applying timeless principles of user-centered design. This book focuses on practical ......一起来看看 《Sexy Web Design》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具