6

I have a problem with ComboBox control on WPF.

I tried to set IsTabStop property to control but it don't works as expected.

If ComboBox is not editable, IsTabStop works correctly, but if ComboBox is editable it always take the focus from keyboard navigation. IsTabStop = false has no effect!

Furthermore, when ComboBox is editable and IsTabStop is true, keyboard navigation to previous control is "locked"..."Shift+Tab" doesn't works!

Is this a WPF bug? Is there any workaround?

I'm using .Net 4.0.

This is an example...

<Window
   x:Class="MainWindow"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   Title="MainWindow"
   Height="250"
   Width="600">

   <StackPanel
     Orientation="Horizontal"
     VerticalAlignment="Center">
     <TextBox
        Width="50"
        IsTabStop="True">
     </TextBox>
    <ComboBox
        Name="cmb1"
        Margin="10,0,0,0"
        Width="50"
        IsEditable="True"
        IsTabStop="False">
    </ComboBox>
    <DatePicker
        Name="dp1"
        Margin="10,0,0,0"
        Width="50"
        IsTabStop="True">
    </DatePicker>
    <TextBox
        Margin="10,0,0,0"
        Width="50"
        IsTabStop="False">
    </TextBox>
    <ComboBox
        Name="cmb2"
        Margin="10,0,0,0"
        Width="50"
        IsTabStop="False">
    </ComboBox>
    <ComboBox
        Name="cmb3"
        Margin="10,0,0,0"
        Width="50"
        IsEditable="True"
        IsTabStop="True">
    </ComboBox>

   </StackPanel>
 </Window>

try to navigate with tab from first textbox to last combobox..."cmb1" take focus also with IsTabStop=False, "cmb2" is ok bacause it's not editable, on "cmb3" it's not possible return to previous control with Shift+Tab.

Also DatePicker seems have same issue.

1
  • can u give quick XAML to replicate that problem ?
    – Bek Raupov
    Jul 5, 2011 at 8:47

2 Answers 2

5

A bit late, but I was looking this exact same issue up the other day. I found that KeyboardNavigation.TabNavigation="None" solves the problem.

1
  • 2
    Nice. For the record I had to use TabStop="False" AND KeyboardNavigation.TabNavigation="None" to get this to work as expected. WPF being WPF again.... Aug 29, 2013 at 14:39
2

yeah seems to be the issue with ComboBox, somebody raised it with microsoft:

Have a look here. It seems to have a workaround.

Here is a workaround. In the Loaded event of your window/control place this code:

var textBox = myCbo.Template.FindName("PART_EditableTextBox", myCbo) as TextBox;
if (textBox != null)
   textBox.IsTabStop = myCbo.IsTabStop;

Change myCbo for your combobox name.

5
  • have a look at workaround tab in the link provided, does that solve your problem ?
    – Bek Raupov
    Jul 5, 2011 at 10:25
  • Okok...I solve. I've created a my CustomComboBox that extend standard ComboBox and on OnApplyTemplate method I've found the editable textbox and I've assigned IsTabStop property for textbox equals to IsTabStop of ComboBox. Jul 5, 2011 at 12:51
  • For "Shift+Tab" issue, I've menaged it on KeyDown event of editable textbox...in this way: Jul 5, 2011 at 12:54
  • if (e.Key == Key.Tab && Keyboard.Modifiers == ModifierKeys.Shift && IsEditable && IsTabStop) { TraversalRequest tRequest = new TraversalRequest(FocusNavigationDirection.Previous); UIElement keyboardFocus = this as UIElement; if (keyboardFocus != null) keyboardFocus.MoveFocus(tRequest); e.Handled = true; } Jul 5, 2011 at 12:57
  • Link is dead. Always best to re-post the relevant info along with the link so that link rot does not make your answer useless.
    – Vaccano
    Jan 22, 2013 at 5:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.