Keyboard won't dismiss even after Focus change

后端 未结 5 1899
忘掉有多难
忘掉有多难 2020-12-19 06:05

I am creating a Windows 8.1 app and after the user presses a button, a popup opens over most of the screen. There are several textboxes inside the popover.

I found

相关标签:
5条回答
  • 2020-12-19 06:14

    It was impossible to programmatically manage the touch-keyboard's appearance and disappearance. Unfortunately, changing the IsEnabled property didn't work for me.

    The touch-keyboard appearance principle was known as Focus-driven, but I had walked out by setting the property IsTabStop=True on the UserControl explicitly. Besides, the TextBox won't activate the touch-keyboard if its IsTabStop=false.

    In theory, I think the system searches the next potential TextBox, so that if so it wasn't to close and re-open, with touchable+inputable property. Maybe there were kind of bug that while releasing the Focus, current TextBox releases only his "touchable" focus, and didn't finish to release the keyboard's "inputable" focus, because that by default only the input-controls have Tab-Stoppable property.

    By the way, if we close the UserControl by a CustomControl's Close button, the IsTabStop=true will be needed on his parent.

    PS: Solution tested only on Windows 8.1 Store Application.

    0 讨论(0)
  • 2020-12-19 06:20

    Please check my answer to my own question:

    https://stackoverflow.com/a/24252140/126537

    Based on @Paul 's answer. Not very elegant, but works as charm.

    0 讨论(0)
  • 2020-12-19 06:21

    In UWP Windows 10 simple disable/enable doesn't work anymore. But this works:

                TextBox.IsEnabled = false;
    
                var t = new DispatcherTimer();
                t.Interval = new TimeSpan(0, 0, 1);
                t.Tick += (a, b) =>
                {
                    t.Stop();
                    TextBox.IsEnabled = true;
                };
                t.Start();
    

    Find more elegant solution? Please share.

    0 讨论(0)
  • 2020-12-19 06:34

    When the textbox that shows the virtual keyboard was disabled it will dismiss the virtual keyboard. so the solution is set the textbox property IsEnabled to false and set it again to true so it can be use again.

    TextBox.KeyDown += (s, a) => {
     if (a.Key == VirtualKey.Enter) {
       TextBox.IsEnabled = false;
       TextBox.IsEnabled = true;
     }
    
    0 讨论(0)
  • 2020-12-19 06:36

    In my app this works fine:

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        this.KeyDown += Strona_KeyDown;
    }
    
    private void Strona_KeyDown(object sender, KeyRoutedEventArgs e)
    {
        if (e.Key == Windows.System.VirtualKey.Enter)
        {
            this.Focus(FocusState.Pointer);
        }
    }
    
    0 讨论(0)
提交回复
热议问题