在WindowsPhone/Windows 8.1上按Enter键时如何隐藏软键盘?

Dav*_*las 2 c# windows-phone-8 windows-8.1

我想在编辑TextBox时按下输入/返回键时隐藏软键盘.这是我到目前为止在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
        }
    }
Run Code Online (Sandbox Code Playgroud)

Igo*_*lic 8

尝试短暂禁用然后启用TextBox.

if(e.Key == VirtualKey.Enter)
{
    textBox.IsEnabled = false;
    textBox.IsEnabled = true;
}
Run Code Online (Sandbox Code Playgroud)


小智 5

private void BobbinRunningLength_KeyUp(object sender, KeyRoutedEventArgs e)
    {
        if (e.Key == VirtualKey.Enter)
        {
            this.Focus(FocusState.Programmatic);
        }
    }
Run Code Online (Sandbox Code Playgroud)

这对我有用.