BUG: ListBox loses keyboard focus when switching tabs

Docking/MDI for WPF Forum

Posted 14 years ago by SledgeHammer01
Version: 9.2.0515
Platform: .NET 4.0
Environment: Windows XP (32-bit)
Avatar
Easy to reproduce, occurs in the samples too...

1) Open up the external ActiPro Docking & MDI Features Demo
2) Click on "Output" window and select the 3rd or 4th item for example
3) Click on the "Find Results 1" tab right next to it
4) Now click on "Output" tab again
5) Press the DOWN ARROW

Notice how the listbox item selection has now gone to Item #1.

EDIT: I understand that the listbox in the demo is selecting the last item automatically, in my case, I am not.

However, I see the same issue where pressing the DOWN ARROW shoots it back to Item #1. So does the UP ARROW.

[Modified at 03/24/2010 06:32 PM]

Comments (5)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

This is actually an issue with the ListBox. When you switch to the Output tab, we are simply passing focus to the first focusable element (which in this case is the ListBox). You can verify this by updating our Docking & MDI features sample with the following code:
<docking:ToolWindow x:Name="outputToolWindow" Title="Output" ImageSource="/Resources/Images/Output16.png">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <ListBox x:Name="eventsListBox" BorderThickness="0" />
        <TextBlock Grid.Row="1" Text="{Binding ElementName=eventsListBox, Path=IsFocused}" />
    </Grid>
</docking:ToolWindow>
If you open up ListBox.OnKeyDown in .NET Reflector, you can see how it handles the arrow keys. If the ListBox has focus, it will always navigate to the first item. If a ListBoxItem has focus, then it will move to the next/previous item. You could handle the IsKeyboardFocusedChanged/GotFocus event on the ListBox, and forward the focus to the selected item. You could also wrap up this into an attached behavior so you can reuse it for any ListBox.


Actipro Software Support

Posted 14 years ago by SledgeHammer01
Avatar
Shouldn't you be setting focus to the last focused item in that tab? Picture this scenario:

A toolwindow has 3 edit boxes... I'm in the 2nd one and switch tabs for a sec... now focus is back on the 1st one. Thats going to be annoying :).

If you set focus to the last focused item as expected, you would resolve the issue with the listbox too.

I don't think always setting focus to the first item is correct. That only makes sense the first time you click on the tab.

The way you have it now will break any scenario that has multiple focusable items.

[Modified at 03/25/2010 03:53 PM]
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
We've marked down a TODO item to look into this sometime after 2010.1 is out.


Actipro Software Support

Posted 13 years ago by baumarc
Avatar
Is this bug already fixed? I run in a similiar problem with "Version 2010.2 build 0533".

[Modified at 01/13/2011 11:01 AM]
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
This is still on our TODO list. This is actually a general WPF issue with controls such as the native WPF TabControl (which our tabs mimic). In the example above, the ListBox in the Output window is freed/released when you switch tabs, as the content of the Find Results is loaded.

The issue ultimately comes down to tracking the element that previously had focus. But in this case, the previous element may or may not be present in the new content.


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.