开发者

WPF Toolbar does not pass focus to the next control on tab-key

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

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.

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

Why? And how ca开发者_运维百科n 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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜