FocusManager Focus Scope For Tab Control
Posted: 07 Jan 2025, 16:36
Is it possible to use FocusManager.IsFocusScope="True" to manage focus on separate tabs of a tab control? Ideally, each tab would remember which element most recently had focus and return focus to this element when the tab is visible again. Testing locally, focus doesn't seem to be updating when the tabs are switched. I have also tried moving the FocusManager.IsFocusScope property to the inside of the CustomControlTab1 (onto the UserControl, the root grid, and the stack panel) without any luck.
Am I missing something? Is there a better way to do this?
Am I missing something? Is there a better way to do this?
Code: Select all
<TabControl x:Name="MyTabControl" SelectedIndex="{Binding ActiveTabIndex}">
<TabItem x:Name="Tab1">
<local:CustomControlTab1 FocusManager.IsFocusScope="True"/>
</TabItem>
<TabItem x:Name="Tab2">
<local:CustomControlTab2 FocusManager.IsFocusScope="True"/>
</TabItem>
<TabItem x:Name="Tab3">
<local:CustomControlTab3 FocusManager.IsFocusScope="True"/>
</TabItem>
<TabItem x:Name="Tab4">
<local:CustomControlTab4 FocusManager.IsFocusScope="True"/>
</TabItem>
</TabControl>Code: Select all
<UserControl
x:Class="CustomControlTab1"
>
<Grid x:Name="Root" Width="1700">
<ScrollViewer x:Name="Container" KeyboardNavigation.DirectionalNavigation="Contained" KeyboardNavigation.TabNavigation="Contained" KeyboardNavigation.ControlTabNavigation="Contained">
<StackPanel>
<!-- various focusable elements arranged vertically -->
</StackPanel>
</ScrollViewer>
</Grid>
</UserControl>