We're using tabnavigation for people, who dont want or can't use the mouse.
When i navigate via tab into the Listbox, the first item will be focused but not selected. When i tab again, the second item will be selected as well. For me it's a strange behavior.
How is it possible to select the first item on tab focus as well?
Thanks!
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBox Text="Focus"/>
<ListBox Grid.Row="1" KeyboardNavigation.TabNavigation="Continue">
<ListBoxItem Content="Test1"/>
<ListBoxItem Content="Test2"/>
<ListBoxItem Content="Test3"/>
</ListBox>
</Grid>
Generally, users won't expect the tabulator key to modify the current selection: They tab around to focus different controls, and then select items using the arrow keys and/or space. It seems like a bug in WPF's ListBox implementation that KeyboardNavigation.TabNavigation="Continue"
not only modifies the current Keyboard Focus, but also selects an item.
If you still want the focused item to be selected, you could just add an event handler (or corresponding behavior) to your list box:
private void OnListBoxGotFocus(object sender, RoutedEventArgs e)
{
if (e.OriginalSource is ListBoxItem listBoxItem)
{
listBoxItem.IsSelected = true;
}
}