English 中文(简体)
如何隐藏在 EditText 软键盘窗口 8 Metro 应用程序上?
原标题:how to hide on EditText soft keyboard windows 8 Metro Application?

我正在使用 C# 在我的框架中有一个编辑文本和一个按钮。 在编辑字段中写入并点击按钮后, 我想隐藏虚拟软键盘 。

最佳回答

您无法了解有关< a href=> 的行为的更多信息。 http:// msdn. microsoft.com/ en- us/library/windows/ apps/hh465404.aspx" rel=“ nofollow” >Input Hosting 管理员和 Soft Keyboard , 您可以 < a href=" http://msdn.microsoft.com/ en- us/library/windows/apps/indows/windows. ui. view management. inputppane.aspx" rel=“ nofolvection” > register 来知道它何时显示或成为隐藏 < /a>。 但是, 您无法在程序上控制它上还是下进行控制 。

问题回答

添加一个假按钮并设定焦点, 键盘将被隐藏 。

Thanks for your question. i have get a better solution for this problem. like this

首先我们可以在 xaml 中添加处理器

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

然后我们把当前页面的焦点集中到后面,效果很好。

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

当显示虚拟键盘的文本框被设置为错误, 虚拟键盘就会消失。 之后我们可以立即设定为真实, 而虚拟键盘会一直被隐藏。 就像这样 :

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

尝试设置文本框的 < code> IsRead only 属性。

我在做一些"相似"的事

    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;
    }

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

在文本框只读的情况下, 启动 < code> KeyDown 事件, 这样您就可以直接使用数据设置您的视图模型并更新您的文本框 ;)

I had the same problem, only with a little difference. When I switched from a textbox to a datepicker the softkeyboard won t disappear.

我尝试了所有你的建议,但没有什么能如愿以偿。 每次我尝试了上述解决方案之一(或者说其他的堆积线 ), 每当我的订婚者有奇怪的行为时,我都会尝试其中之一(或者说其他的堆积线 ) 。

过了一段时间后,我通过Google找到了一些东西,它就像一个魅力。Hhere

在评论部分Dusher16写下了一个非常干净的解决方案,它也适用于WinRT/Win8/Win8.1/Metro或如何称呼它。

<强> 创建新等级:

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();
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签