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?

Michael
  • 1,081
  • 1
  • 12
  • 27
  • 1
    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`? – Fredrik Hedblad Jun 06 '12 at 22:04
  • 1
    What happens when you set `Focusable="False"` on the ContentControl? – Kyeotic Jun 06 '12 at 23:27

2 Answers2

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"
jimmyjambles
  • 1,631
  • 2
  • 20
  • 34
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"
Eternal21
  • 4,190
  • 2
  • 48
  • 63