WPF工具栏不会将焦点传递给tab键上的下一个控件

时间:2022-04-03 19:41:42

I have created a simple WPF application with a TextBox and a Toolbar containing two buttons.

我创建了一个简单的WPF应用程序,其中包含TextBox和包含两个按钮的工具栏。

When I click the textbox and press the tab-key, input focus is moved to the first toolbar button. Pressing tab again moves input to the next tab button. So far, so good. But pressing tab again moves input focus to the first toolbar button, where it should have been moved to the text box.

当我单击文本框并按Tab键时,输入焦点将移动到第一个工具栏按钮。再次按下选项卡将输入移动到下一个选项卡按钮。到现在为止还挺好。但再次按Tab键将输入焦点移动到第一个工具栏按钮,它应该已移动到文本框。

So once the toolbar receives input focus, it stays there, and you cannot move focus out except using the mouse.

因此,一旦工具栏接收到输入焦点,它就会停留在那里,除了使用鼠标之外,您无法移动焦点。

Why? And how can I remedy that?

为什么?我该如何解决这个问题呢?

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="WpfApplication1.MainWindow"
    x:Name="Window"
    Title="MainWindow"
    Width="640" Height="480">

    <StackPanel x:Name="LayoutRoot">
        <ToolBar VerticalAlignment="Top">
            <Button Content="Test1" />
            <Button Content="Test2" />
        </ToolBar>
        <TextBox />
    </StackPanel>
</Window>

1 个解决方案

#1


16  

The solution is quite simple, you just have to add KeyboardNavigation.TabNavigation="Continue" to your ToolBar. Then the focus gets passed back to the TextBox again.

解决方案非常简单,只需将KeyboardNavigation.TabNavigation =“Continue”添加到ToolBar即可。然后焦点再次传回TextBox。

#1


16  

The solution is quite simple, you just have to add KeyboardNavigation.TabNavigation="Continue" to your ToolBar. Then the focus gets passed back to the TextBox again.

解决方案非常简单,只需将KeyboardNavigation.TabNavigation =“Continue”添加到ToolBar即可。然后焦点再次传回TextBox。