Windows phone 7 如何在WP7中隐藏软键盘?

Windows phone 7 如何在WP7中隐藏软键盘?,windows-phone-7,soft-keyboard,Windows Phone 7,Soft Keyboard,在文本框中输入。 键入enter键后,我想隐藏软键盘。 如何在代码中实现它 private void OnKeyDownHandler(object sender, KeyEventArgs e) { if (e.Key != Key.Enter) return; ...} this.focus() 这将使文本框中的焦点丢失。它基本上把焦点放在页面上。您还可以将文本框转换为只读,以禁

在文本框中输入。 键入enter键后,我想隐藏软键盘。 如何在代码中实现它

private void OnKeyDownHandler(object sender, KeyEventArgs e)
           {
                if (e.Key != Key.Enter)
                   return;         

...}
this.focus()
这将使文本框中的焦点丢失。它基本上把焦点放在页面上。您还可以将文本框转换为
只读
,以禁止任何进一步的输入


隐藏SIP只需将焦点从文本框更改为页面上的任何其他元素即可。它不必是this.focus(),它可以是anyElement.focus()。只要元素不是您的文本框,SIP就应该隐藏自己。

我使用以下方法关闭SIP:

/// 
/// Dismisses the SIP by focusing on an ancestor of the current element that isn't a
/// TextBox or PasswordBox.
/// 
public static void DismissSip()
{
    var focused = FocusManager.GetFocusedElement() as DependencyObject;

    if ((null != focused) && ((focused is TextBox) || (focused is PasswordBox)))
    {
        // Find the next focusable element that isn't a TextBox or PasswordBox
        // and focus it to dismiss the SIP.
        var focusable = (Control)(from d in focused.Ancestors()
                                  where
                                    !(d is TextBox) &&
                                    !(d is PasswordBox) &&
                                    d is Control
                                  select d).FirstOrDefault();
        if (null != focusable)
        {
            focusable.Focus();
        }
    }
 }

祖先
方法来自Colin Eberhardt。该代码与Enter键处理程序结合使用,用于“切换”到下一个文本框或密码框,这就是为什么在选择中会跳过这些文本框或密码框的原因,但如果对您有意义,您可以将它们包括在内。

谢谢。但是我不能用它。因为我只找到这个.SearchTxt.Focus(),意思是获取焦点。但是没有为文本框设置焦点。隐藏SIP可以通过简单地将焦点从文本框更改为页面上的任何其他元素来完成。它不必是
this.focus()
,它可以是
anyElement.focus()
。只要元素不是您的文本框,SIP就应该隐藏自己。
this.Focus()
对我不起作用。我不得不在我的页面上创建一个新的假
按钮
,宽度为0,并将其聚焦。