David Douglas David Douglas - 1 month ago 9
C# Question

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
}
}

Answer

Try shortly disabling and then enabling the TextBox.

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