Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am creating a Windows 8.1 app and after the user presses a button, a popup opens over most of the screen. There are several textboxes inside the popover.

I found this sample code from microsoft about how to detect the appearance of the on-screen keyboard.

I have also found the following SO posts and sites basically informing that there is no way to force the keyboard to close, and the correct thing to do is in fact programmatically focus a hidden element on the page or disable and then re-enable the textbox:

So I followed the advice and created an invisible button. When the user taps the close button, it is supposed to give focus to that button and dismiss the keyboard. What happens is the textbox does lose focus, but the keyboard does not go away. If I cause the close button to give focus to the hidden button and close the popup (which is the desired effect), the keyboard does not go away until the view (that was previously under the popup) is tapped.

How can I make closing the popup cause the keyboard to dismiss?

EDIT: It appears that there might be a way to programmatically dismiss the keyboard because triggering the App Bar to open while the keyboardi s open automatically dismisses the keyboard.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
493 views
Welcome To Ask or Share your Answers For Others

1 Answer

When the textbox that shows the virtual keyboard was disabled it will dismiss the virtual keyboard. so the solution is set the textbox property IsEnabled to false and set it again to true so it can be use again.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...