TabbedMdiHost returns to last tab after click on any button

Docking/MDI for WPF Forum

Posted 3 years ago by Sergei Svekolnikov
Version: 16.1.0632
Platform: .NET 4.5
Environment: Windows 10 (64-bit)
Avatar

I have a project with TabbedMdiHost and tabs with ToolBar, when I create come tabs switch between them and then click any button on ToolBar i get switched back to last tab.

Here I created a small project to reproduce issue

https://1drv.ms/u/s!AsrtdLXc2hes9xHDuZixiOx6nR3i

 

Steps to reproduce:

  1. Add some tabs
  2. Switch between tabs many times without clicking inside
  3. Click any button on ToolBar
  4. If tab did not switch back to last after click - try again, it is kinda random

Comments (5)

Answer - Posted 3 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Sergei,

First do you have the latest build from our site?  If so, try changing your tab indices in the TestControl controls so that the content looks like this:

<DockPanel>
        
    <ToolBarTray DockPanel.Dock="Top">
        <ToolBar TabIndex="1">
            <Button Content="Button 1" />
            <Button Content="Button 2" />
            <Button Content="Button 3" />
        </ToolBar>
    </ToolBarTray>
        
    <ContentControl TabIndex="0"/>
        
</DockPanel>

The reason I say that is that this setup would allow a focusable control (the ContentControl) to get focus first when the tab is clicked.  We try to track the last focused element when switching off a tab, so that focus can be restored properly again later.  Perhaps if the tool bar had focus within the tab only, and nothing else did beforehand, that triggered the issue.  Give that a try and let us know if it resolves the problem.


Actipro Software Support

Posted 3 years ago by Sergei Svekolnikov
Avatar

Hi, yes, it works fine for me, thanks, but can confuse someone, who may need to have TabIndex="0" on something else.

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

Hi Sergei,

I'm not really able to reproduce the issue when testing, even with the original code you sent.  Can you give me an exact series of steps with the original sample that make it occur?  Thanks!


Actipro Software Support

Posted 3 years ago by Sergei Svekolnikov
Avatar

Hi, I created a screencast for you

https://1drv.ms/v/s!AsrtdLXc2hes9xJs3ftE3Tkpq3n8

Look at the end of video, when I open last tab and click on a button on toolbar - it suddenly switches to second tab

When I set TabIndex="0" on ContentControl it starts working fine

<ContentControl TabIndex="0"/>
Posted 3 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Sergei,

Thank you for the video.  I spent a while on this today.  While I am not seeing the tab switch, I do see the focus moving back up to the Window and the tab deactivating when following the same steps.  It doesn't appear to be any focusing we're doing since I debugged all the places we set focus and they never get hit.  My guess is that it's because the ToolBar is a focus scope and buttons in a separate focus scope like that do Keyboard.Focus(null) when they are clicked, which normally will return focus to the last focused element in the main focus scope.  But for some reason WPF thinks that last focused element is on another tab (in your case) or can't be found and returns to the Window (in our case).  I verified that when you click a tab, we are locating the ContentControl in your TestControl and its Focus() method returns true, so I'm not sure why WPF is getting goofed up with its last focused element tracking.


Actipro Software Support

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.