How to hide soft keyboard in WP7?

In the TextBox input field. After entering, enter the key, I want to hide the soft keyboard. How to do it in codes?

private void OnKeyDownHandler(object sender, KeyEventArgs e) { if (e.Key != Key.Enter) return; ...} 
+4
source share
2 answers

this.focus() This will lose focus from the text box. This basically puts the focus on the page. You can also convert the text field to read only to prevent further input.

SIP hiding can be done simply by changing focus from the text box to any other element on the page. It should not be this.focus (), it can be anyElement.focus (). As long as the item is not your text box, SIP should be hidden.

+27
source

I use the following method to reject 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(); } } } 

The Ancestors method comes from LinqToVisualTree from Colin Eberhardt. The code is used in combination with the Enter Key handler, for "tabbing" for the next TextBox or PasswordBox, so they are skipped when you select, but you can enable them if that makes sense to you.

+2
source

Source: https://habr.com/ru/post/1379066/


All Articles