[英]how to hide soft keyboard in WP7?
在TextBox输入中。 输入密钥后,我想隐藏软键盘。 怎么做代码?
private void OnKeyDownHandler(object sender, KeyEventArgs e)
{
if (e.Key != Key.Enter)
return;
...}
this.focus()
这将允许焦点从文本框中丢失。 它基本上把重点放在页面上。 您还可以将文本框转换为read only
以禁止任何进一步的输入。
只需将焦点从文本框更改为页面上的任何其他元素,即可隐藏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();
}
}
}
Ancestors
方法来自Colin Eberhardt的LinqToVisualTree 。 该代码与Enter键处理程序一起使用,用于“tabbing”到下一个TextBox或PasswordBox,这就是为什么它们在选择中被跳过的原因,但如果它对你有用,你可以包括它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.