# ComboBox

## Common Properties

| Property                   | Description                                                                              |
| -------------------------- | ---------------------------------------------------------------------------------------- |
| `SelectedIndex`            | Gets or sets the index of the selected item.                                             |
| `SelectedItem`             | Gets or sets the selected item.                                                          |
| `SelectedItems`            | Gets the selected items.                                                                 |
| `AutoScrollToSelectedItem` | Gets or sets a value indicating whether to automatically scroll to newly selected items. |
| `SelectionMode`            | Gets or sets the selection mode.                                                         |
| `IsDropDownOpen`           | Gets or sets a value indicating whether the dropdown is currently open.                  |
| `MaxDropDownHeight`        | Gets or sets the maximum height for the dropdown list.                                   |

## Reference

[ComboBox](http://reference.avaloniaui.net/api/Avalonia.Controls/ComboBox/)

## Source code

[ComboBox.cs](https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Controls/ComboBox.cs)

## Examples <a href="#examples" id="examples"></a>

### Basic ComboBox <a href="#basic-combobox" id="basic-combobox"></a>

```markup
<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
        x:Class="AvaloniaAppTemplate.MainWindow"
        Title="AvaloniaAppTemplate">
    <StackPanel>
        <ComboBox SelectedIndex="0">
            <ComboBoxItem>Inline Items</ComboBoxItem>
            <ComboBoxItem>Inline Item 2</ComboBoxItem>
            <ComboBoxItem>Inline Item 3</ComboBoxItem>
            <ComboBoxItem>Inline Item 4</ComboBoxItem>
        </ComboBox>
    </StackPanel>
</Window>
```

### ComboBox with custom item templates <a href="#combobox-with-custom-item-templates" id="combobox-with-custom-item-templates"></a>

```markup
<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
        x:Class="AvaloniaAppTemplate.MainWindow"
        Title="AvaloniaAppTemplate">
    <StackPanel>
        <ComboBox SelectedIndex="0">
            <ComboBoxItem>
                <Panel>
                    <Rectangle Fill="{DynamicResource ThemeAccentBrush}"/>
                    <TextBlock Margin="8">Control Items</TextBlock>
                </Panel>
            </ComboBoxItem>
            <ComboBoxItem>
                <Ellipse Width="50" Height="50" Fill="Yellow"/>
            </ComboBoxItem>
            <ComboBoxItem>
                <TextBox Text="TextBox"/>
            </ComboBoxItem>
      </ComboBox>
    </StackPanel>
</Window>
```

### ComboBox with binding <a href="#combobox-with-binding" id="combobox-with-binding"></a>

This example binds the fonts installed to a ComboBox

```markup
<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
        x:Class="AvaloniaAppTemplate.MainWindow"
        Title="AvaloniaAppTemplate">
    <StackPanel>
        <ComboBox x:Name="fontComboBox"  SelectedIndex="0">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Name}" FontFamily="{Binding}" />
                </DataTemplate>
            </ComboBox.ItemTemplate>
       </ComboBox>
    </StackPanel>
</Window>
```

With this code behind:

```csharp
var fontComboBox = this.Find<ComboBox>("fontComboBox");
fontComboBox.Items = FontManager.Current.GetInstalledFontFamilyNames().Select(x => new FontFamily(x));
fontComboBox.SelectedIndex = 0;
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://avaloniachina.gitbook.io/avalonia/docs/controls/combobox.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
