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?

John
  • 151
  • 1
  • 1
  • 7
  • Does setting `Focusable="False"` make any difference? – Fredrik Hedblad Feb 22 '11 at 13:50
  • Normally IsTabStop works fine, w/o ElementHost – H H Feb 22 '11 at 14:15
  • 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. – John Feb 22 '11 at 14:27
  • 3
    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. – John Feb 22 '11 at 15:20
  • 1
    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. – Astrogator Dec 02 '14 at 21:14
  • @Astrogator: hit probably the same problem with `UserControl` that has its `ItemsSource` assigned (and that probably resets `IsTabStop`). Pretty unnerving. – z33k Aug 13 '21 at 14:22
  • @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. – z33k Aug 13 '21 at 15:50

2 Answers2

12

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

DanT
  • 3,960
  • 5
  • 28
  • 33
1

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

"Focusable=False" 
patrick
  • 16,091
  • 29
  • 100
  • 164