IsTabStop="False" has no effect on my WPF app
Asked Answered
P

2

9

I'm having a really hard time with something that should be trivial. I just want to remove a few buttons from the tab order on a UserControl. I've tried adding IsTabStop="False" and KeyboardNavigation.IsTabStop="False" attributes to their xaml declarations, as well as setting myButton.IsTabStop = false; in the Loaded event handler for the UserControl. None of these additions had any effect, I could still tab to the controls I did this for.

Setting the TabIndex in the xaml works fine. The UserControl is being displayed in a WPFElementHost if that might make a difference. The other thought I had was that I might need to specify the TabIndex for all the other controls, but I haven't read that anywhere and I'd prefer to not state that explicitly if possible. Does anyone have a guess as to what might be going wrong?

Panthia answered 22/2, 2011 at 13:47 Comment(7)
Does setting Focusable="False" make any difference?Seesaw
Normally IsTabStop works fine, w/o ElementHostDetoxicate
Good thought, but Focusable="False" did not change the behavior. I can still tab to the button in question. Also, I tried it in combination with the IsTabStop="False" attribute, as well as by itself.Panthia
So I realized that the buttons I'm trying to remove from the tab order were actually buttons nested inside custom UserControls, so I was setting the UserControls' IsTabStop property, but the inner button wasn't aware of the change. This solved part of the problem, but I am still unable to remove several ListBoxes from the tab order - they ignore my attempts.Panthia
Similar scenario: a ListBox. While empty, .IsTabStop=false is enough to exclude it from tab-sequence. Once its .ItemsSource is assigned, it is included. Then data is reset, and it's not in sequence; then data is set again - and it's in. And again, and again.. Setting .Focusable=false in addition has no effect.Theodoretheodoric
@Astrogator: hit probably the same problem with UserControl that has its ItemsSource assigned (and that probably resets IsTabStop). Pretty unnerving.Plast
@Astrogator: found a solution. Actually my problem was a little different as I had UserControl based on ItemsControl and kept setting IsTabStop on the user control to no avail when in fact my items control inside it kept getting focus with tab circulation. Setting IsTabStop on the items control solved the issue.Plast
C
13

Try setting KeyboardNavigation.TabNavigation ="None" in the parent control.

Calefacient answered 29/11, 2011 at 13:5 Comment(1)
That would disable all tabstops - not usable when some lements should be hit by tab.Cryometer
P
1

You need also employ KeyboardNavigation.TabNavigation ="Continue" for the parent controls, and

"Focusable=False" 
Palmetto answered 20/3, 2013 at 14:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.