1
votes

I am trying to style a WPF combo box. Everything is working except when IsEditable="true", Shift+Tab refuses to move back to the previous control. It seems like the contained TextBox is just reselected each time Shift+Tab is pressed. Tab works fine.

I'm using the MS published source code here: https://docs.microsoft.com/en-us/dotnet/desktop/wpf/controls/combobox-styles-and-templates?view=netframeworkdesktop-4.8

There is an issue reported on github, here: https://github.com/dotnet/docs/issues/11552

But no one has provided a solution.

I've tried all the obvious things included adding TabIndex to all the controls in the window which was suggested in another answer, and also setting KeyboardNavigation.TabNavigation to both "None" and "Local". What am I missing?

An unstyled combo box works fine.

1

1 Answers

2
votes

You have to remove the tab stop (IsTabStop="False") from the ComboBox, if in edit mode (IsEnabled="True"). It's best to add a corresponding trigger to the Style:

<Style TargetType="{x:Type ComboBox}">

  ...

  <Style.Triggers>
    <Trigger Property="IsEditable" Value="true">
      <Setter Property="IsTabStop" Value="false"/>
    </Trigger>
  </Style.Triggers>
</Style>

It's always best to extract the template using the XAML designer by right clicking on the selected control (in the design view) and select "Edit Template | Edit a Copy..." or alternatively use Visual Studio Blend to modify the control's original style. The styles and templates provided by Microsoft Docs are not always accurate. The original style (when extracted using Visual Studio or Blend) already has this trigger, that is missing in the Microsoft Docs version, defined.