Close WinRT virtual keyboard programatically

Is it really not possible to close a virtual keyboard programatically?

It turns out showing and hiding the virtual keyboard is not possible by design. The keyboard shows up when a textbox gets the focus and the keyboard hides when another element gets the focus.

surface keyboard

Setting the focus to another element programatically did not work for me when I used clearButton.Focus(Windows.UI.Xaml.FocusState.Programmatic);


When the textbox that showed the virtual keyboard has property IsEnabled set to false, the virtual keyboard disappears. We can immediately set is to true after that and the virtual keyboard will remain hidden. Here is how to do it:

searchTextBox.KeyDown += (s, a) => {
    if (a.Key == VirtualKey.Enter) {
        searchTextBox.IsEnabled = false;
        searchTextBox.IsEnabled = true;
Written by Loek van den Ouweland on May 22, 2013. Questions regarding this artice? You can send them to the address below.
By using this site, you acknowledge that you have read and understand our Cookie and Privacy Policy.