ComboBox

Dropdown selection control with popup item list.

Overview

ComboBox extends Selector and provides a compact dropdown selection control. When closed, it displays the currently selected item alongside a dropdown arrow indicator. Pressing Enter, Space, or clicking the control opens a popup list of available items. The popup respects MaxDropDownHeight and scrolls when the item count exceeds the visible area. Selecting an item closes the dropdown and updates SelectedItem and SelectedIndex.

Basic Example

<StackPanel Orientation="Vertical">
  <TextBlock Text="Select a fruit:" />
  <ComboBox SelectedIndex="0">
    <ComboBoxItem Content="Apple" />
    <ComboBoxItem Content="Banana" />
    <ComboBoxItem Content="Cherry" />
    <ComboBoxItem Content="Date" />
  </ComboBox>
</StackPanel>

Properties

PropertyTypeDefaultDescription
IsDropDownOpenboolfalseWhether the dropdown popup is currently open.
MaxDropDownHeightint8Maximum number of visible rows in the dropdown before scrolling.
FocusColorColorCyanBorder color when the control has focus.
HoverColorColorYellowBorder color when the mouse hovers over the control.
SelectedBackgroundColorBlueBackground color of the highlighted item in the dropdown.
SelectedForegroundColorWhiteForeground color of the highlighted item in the dropdown.
SelectedIndexint-1Zero-based index of the currently selected item. Inherited from Selector.
SelectedItemobjectnullThe currently selected item object. Inherited from Selector.
ItemsSourceIEnumerablenullData source for generating items. Inherited from ItemsControl.
ItemTemplateDataTemplatenullTemplate for rendering each item. Inherited from ItemsControl.

Creating Items

Inline ComboBoxItem Elements

<ComboBox SelectedIndex="0">
  <ComboBoxItem Content="Option A" />
  <ComboBoxItem Content="Option B" />
  <ComboBoxItem Content="Option C" />
</ComboBox>

String ItemsSource Binding

<ComboBox ItemsSource="{Binding AvailableColors}"
          SelectedItem="{Binding SelectedColor, Mode=TwoWay}" />

ItemTemplate for Custom Display

<ComboBox ItemsSource="{Binding Users}" SelectedIndex="0">
  <ComboBox.ItemTemplate>
    <DataTemplate>
      <TextBlock Text="{Binding DisplayName}" />
    </DataTemplate>
  </ComboBox.ItemTemplate>
</ComboBox>

Examples

ComboBox with Pre-Selected Item

<ComboBox SelectedIndex="2">
  <ComboBoxItem Content="Low" />
  <ComboBoxItem Content="Medium" />
  <ComboBoxItem Content="High" />
  <ComboBoxItem Content="Critical" />
</ComboBox>

Custom Dropdown Height

<ComboBox MaxDropDownHeight="4" SelectedIndex="0">
  <ComboBoxItem Content="January" />
  <ComboBoxItem Content="February" />
  <ComboBoxItem Content="March" />
  <ComboBoxItem Content="April" />
  <ComboBoxItem Content="May" />
  <ComboBoxItem Content="June" />
  <ComboBoxItem Content="July" />
  <ComboBoxItem Content="August" />
</ComboBox>

Styled ComboBox

<ComboBox SelectedIndex="0"
          FocusColor="Magenta"
          SelectedBackground="DarkCyan"
          SelectedForeground="White">
  <ComboBoxItem Content="Debug" />
  <ComboBoxItem Content="Info" />
  <ComboBoxItem Content="Warning" />
  <ComboBoxItem Content="Error" />
</ComboBox>

Keyboard Shortcuts

KeyAction
EnterOpen the dropdown (when closed) or select the highlighted item and close (when open).
SpaceOpen the dropdown (when closed) or select the highlighted item and close (when open).
EscapeClose the dropdown without changing selection.
Up ArrowWhen closed: cycle to previous item. When open: move highlight up.
Down ArrowWhen closed: cycle to next item. When open: move highlight down.
HomeMove highlight to the first item (when open).
EndMove highlight to the last item (when open).

Key Concepts