Search code examples
c#windows-phone-8windows-8.1

How to hide the Soft Keyboard when Enter key is pressed on WindowsPhone / Windows 8.1?


I want to hide the Soft Keyboard when enter/return key is pressed from editing a TextBox. This is what I have so far in c#:

private void SearchBox_KeyUp(object sender, KeyRoutedEventArgs e)
    {
        TextBox textBox = sender as TextBox;
        if(e.Key == VirtualKey.Enter)
        {
            this.Focus(FocusState.Programmatic); // sending focus to Page to hide keyboard
        }
    }

Solution

  • Try shortly disabling and then enabling the TextBox.

    if(e.Key == VirtualKey.Enter)
    {
        textBox.IsEnabled = false;
        textBox.IsEnabled = true;
    }