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;