ComboBox
A drop-down list control.

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​

Source code

​ComboBox.cs​

Examples

Basic ComboBox

1
<Window xmlns="https://github.com/avaloniaui"
2
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
4
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
6
x:Class="AvaloniaAppTemplate.MainWindow"
7
Title="AvaloniaAppTemplate">
8
<StackPanel>
9
<ComboBox SelectedIndex="0">
10
<ComboBoxItem>Inline Items</ComboBoxItem>
11
<ComboBoxItem>Inline Item 2</ComboBoxItem>
12
<ComboBoxItem>Inline Item 3</ComboBoxItem>
13
<ComboBoxItem>Inline Item 4</ComboBoxItem>
14
</ComboBox>
15
</StackPanel>
16
</Window>
Copied!

ComboBox with custom item templates

1
<Window xmlns="https://github.com/avaloniaui"
2
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
4
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
6
x:Class="AvaloniaAppTemplate.MainWindow"
7
Title="AvaloniaAppTemplate">
8
<StackPanel>
9
<ComboBox SelectedIndex="0">
10
<ComboBoxItem>
11
<Panel>
12
<Rectangle Fill="{DynamicResource ThemeAccentBrush}"/>
13
<TextBlock Margin="8">Control Items</TextBlock>
14
</Panel>
15
</ComboBoxItem>
16
<ComboBoxItem>
17
<Ellipse Width="50" Height="50" Fill="Yellow"/>
18
</ComboBoxItem>
19
<ComboBoxItem>
20
<TextBox Text="TextBox"/>
21
</ComboBoxItem>
22
</ComboBox>
23
</StackPanel>
24
</Window>
Copied!

ComboBox with binding

This example binds the fonts installed to a ComboBox
1
<Window xmlns="https://github.com/avaloniaui"
2
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
4
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
6
x:Class="AvaloniaAppTemplate.MainWindow"
7
Title="AvaloniaAppTemplate">
8
<StackPanel>
9
<ComboBox x:Name="fontComboBox" SelectedIndex="0">
10
<ComboBox.ItemTemplate>
11
<DataTemplate>
12
<TextBlock Text="{Binding Name}" FontFamily="{Binding}" />
13
</DataTemplate>
14
</ComboBox.ItemTemplate>
15
</ComboBox>
16
</StackPanel>
17
</Window>
Copied!
With this code behind:
1
var fontComboBox = this.Find<ComboBox>("fontComboBox");
2
fontComboBox.Items = FontManager.Current.GetInstalledFontFamilyNames().Select(x => new FontFamily(x));
3
fontComboBox.SelectedIndex = 0;
Copied!
Last modified 6mo ago