如何隐藏的EditText软键盘的Windows 8 Metro应用?(how to hide on

2019-06-24 17:11发布

我有一个EditText和使用C#在我的构图按钮。 编辑栏里面写,点击该按钮后,我想隐藏虚拟软键盘。

Answer 1:

你不能。 有对行为的更多信息, 输入主机管理和软键盘 ,你可以注册知道什么时候它显示或隐藏变 。 但是,你不能编程控制无论是向上或向下。



Answer 2:

添加一个虚拟按钮,将焦点设置到它,键盘将被隐藏。



Answer 3:

谢谢你的问题。 我已经得到了这个问题的更好的解决方案。 像这样

首先我们可以在XAML中添加处理程序

<Grid x:Name= Tapped="Grid_Tapped_1">
  ......
 </Grid >

那么,我们关注当前页面类似如下。 它工作得很好。

private void Grid_Tapped_1(object sender, TappedRoutedEventArgs e)
        {
            this.Focus(FocusState.Programmatic);
        }


Answer 4:

当显示虚拟键盘文本框有它的属性格式的IsEnabled设置为false,虚拟键盘消失。 我们可以立即设置是正确后和虚拟键盘将保持隐藏。 像这样:

MyTextBox.KeyDown += (s, a) => {
    if (a.Key == VirtualKey.Enter) {
        MyTextBox.IsEnabled = false;
        MyTextBox.IsEnabled = true;
    }
};


Answer 5:

尝试设置IsReadOnly的Textbox`的财产。

我在做一些“相似”

    private void textbox_input_LostFocus(object sender, RoutedEventArgs e)
    {
        textbox_input.IsReadOnly = false;
    }

    private void textbox_input_Tapped(object sender, TappedRoutedEventArgs e)
    {
        if(e.PointerDeviceType != Windows.Devices.Input.PointerDeviceType.Mouse)
            textbox_input.IsReadOnly = true;
        else
            textbox_input.IsReadOnly = false;
    }

有了这个剪断我,如果用户不使用鼠标抑制键盘...

另外, KeyDown而文本框是只读的,因此你可以直接利用这些数据来设置您的视图模型,并更新了它的文本框事件被触发;)



Answer 6:

还有就是它可以通过设置容器的隐藏触摸键盘的解决方案IsTabStop=true点击您的按钮为“提交”后,全自动。

但是,顺便说一句,我注意到,进入该页面下一次的EditText (应该是一个TextBox )会自动聚焦,并有触摸式键盘显示。 也许你最好禁用EditText提交后。 (似乎完成并阻断输入操作)



Answer 7:

我有同样的问题,只是有一点差别。 当我从一个文本框切换到日期选择器的softkeyboard不会消失。

我想您的所有建议,但没有什么工作像它应该。 每当我的日期选择器有一个奇怪的现象,我试过上述解决方案的一个(或一些其他计算器线程)之后。

一段时间后,我发现通过谷歌的东西,它的工作就像一个魅力。 这里

在注释部分Dusher16写的很干净的解决方案,其工作方式也为的WinRT /于Win8 / Win8.1 /地铁或你将如何调用它。

创建一个新的类:

using System.Runtime.InteropServices;
using Windows.Devices.Input;

namespace Your.Namespace
{
    public static class TouchKeyboardHelper
    {
        #region < Attributes >

        private const int WmSyscommand = 0x0112; // Flag to received/send messages to the system.
        private const int ScClose = 0xF060; // Param to indicate we want to close a system window.

        #endregion < Attributes >

        #region < Properties >

        public static bool KeyboardAttached
        {
            get { return IsKeyboardAttached(); }
        }

        #endregion < Properties >

        #region < Methods >

        [DllImport("user32.dll")]
        private static extern int FindWindow(string lpClassName, string lpWindowName); // To obtain an active system window handler.

        [DllImport("user32.dll")]
        private static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam); // To send a message to the system.

        /// <summary>
        /// To detect if a real keyboard is attached to the dispositive.
        /// </summary>
        /// <returns></returns>
        private static bool IsKeyboardAttached()
        {
            KeyboardCapabilities keyboardCapabilities = new KeyboardCapabilities(); // To obtain the properties for the real keyboard attached.
            return keyboardCapabilities.KeyboardPresent != 0 ? true : false;
        }

        /// <summary>
        /// To close the soft keyboard
        /// </summary>
        public static void CloseOnscreenKeyboard()
        {
            // Retrieve the handler of the window 
            int iHandle = FindWindow("IPTIP_Main_Window", ""); // To find the soft keyboard window.
            if (iHandle > 0)
            {
                SendMessage(iHandle, WmSyscommand, ScClose, 0); // Send a close message to the soft keyboard window.
            }
        }

        #endregion < Methods >
    }
}

而在例如一些XAML.cs文件添加下面几行:

private void DatePicker_GotFocus(object sender, RoutedEventArgs e)
{
    if (TouchKeyboardHelper.KeyboardAttached)
        TouchKeyboardHelper.CloseOnscreenKeyboard();
}


文章来源: how to hide on EditText soft keyboard windows 8 Metro Application?