Search code examples
c#wpfxamlcomboboxdatatemplate

ComboBox Item Selection Works With Keyboard But Not Mouse


I have a combo box that is not working as I expect at runtime. I can use the mouse to expand the drop-down window, but clicking an item does not seem to select it. The dropdown goes away, but the selection is not changed. The same control seems to work as expected using the keyboard. Arrow up/down changes the selection. I can use the arrow keys to choose and enter to select to change the value as well.

How do I get clicking to select an item?

  <DataTemplate DataType="{x:Type myType}">
    <Border ...>
      <Grid x:Name="upperLayout">
        <Grid x:Name="lowerLayout">
          <ComboBox x:Name="combo"
            Grid.Column="2"
            ItemsSource="{Binding Things}"
            SelectedItem="{Binding SelectedThing}"
            >
            <ComboBox.ItemTemplate>
              <DataTemplate>
                <TextBlock Text="{Binding Name}" />
              </DataTemplate>
            </ComboBox.ItemTemplate>
          </ComboBox>
        </Grid>
      </Grid>
    </Border>
  </DataTemplate>

Solution

  • Root cause was that another developer had implemented some code that changed the focus on the preview mouse down event. This code was updated to have the desired behavior without modifying focus and the combo box now works as expected. The information needed to diagnose was not in the original question (can't publish it all...).