6

I want to hide the soft keyboard when the Enter key is tapped, but no solutions works for me properly. (Windows Phone 8.1 Universal App)

This one just doesn't work:

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

A method like this:

private void LoseFocus(object sender)
{
    var control = sender as Control;
    var isTabStop = control.IsTabStop;
    control.IsEnabled = false;
    control.IsTabStop = false;
    control.IsEnabled = true;
    control.IsTabStop = isTabStop;
}

works only partially. It's hiding keyboard only when I'm using textbox for the first time. On the second time keyboard is reappearing.

1
  • Remember that if you turn IsEnabled off and back on in the same method, the form won't register your changes until after the method completes. You can toggle the value all you want within the method, but only the result after the function is done is what matters.
    – gunr2171
    Commented Oct 31, 2014 at 16:44

3 Answers 3

17

There is direct API support to hide and show the InputPane. You don't need to try to fake out the system.

The Windows.UI.ViewManagement.InputPane.TryShow and TryHide methods are available on Windows Phone 8.1.

The other option would be to move the focus to a more appropriate control when the user hits Enter.

0
9

This is the complete code to hide the keyboard when the user press the enter key

  private void TextBox_KeyUp(object sender, KeyRoutedEventArgs e)
    {
        if(e.Key==Windows.System.VirtualKey.Enter)
        {
            Windows.UI.ViewManagement.InputPane.GetForCurrentView().TryHide();
        }
    }
2

I just did something like that and it's working:

private async void makeRequest(string title, int page)
    {
        myTextBox.IsEnabled = false;
        myTextBox.IsTabStop = false;
        // here is my httprequest and changing itemssource of listview
        myTextBox.IsEnabled = true;
        myTextBox.IsTabStop = true;
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.