How to disable tab stop on a stackpanel
Asked Answered
S

2

18

I have a stackpanel that keeps getting focus when I tab around in the application.

Using snoop I can see that the stackpanel has a ContentControl which has a ContentPresenter. It is the ContentControl that gets the focus. How can I disable this? And why is this default behavior?

Strangury answered 6/6, 2012 at 21:35 Comment(2)
A StackPanel shouldn't be able to get focus unless you set Focusable="True" (default is False). Where is this StackPanel located, Window/UserControl, ItemsControl?Seclusion
What happens when you set Focusable="False" on the ContentControl?Embolden
S
26

This is not the default behavior, if it has been overwritten by some resource then you can reset it with

KeyboardNavigation.IsTabStop="False"

Or alternatively...

FocusManager.IsFocusScope="False"
Sleuth answered 7/6, 2012 at 1:25 Comment(2)
What is the difference between these two approaches?Petrozavodsk
FocusManager.IsFocusScope="False" didn't work for me but KeyboardNavigation.IsTabStop="False" didNorwood
H
10

Had a similar issue with a DataTemplate that was using a StackPanel as container. The DataTemplate was then used for ListBox items. None of the suggestions worked for me to prevent the items from receiving tab stops, until I used the following on the actual listbox:

KeyboardNavigation.TabNavigation="None"
Honey answered 18/12, 2013 at 15:14 Comment(2)
Or by code behind: KeyboardNavigation.SetTabNavigation(control, KeyboardNavigationMode.None);Squireen
How do you do that in UWP? Says "not supported"Wappes

© 2022 - 2024 — McMap. All rights reserved.