Table of Contents

Class ComboBox

Namespace
Avalonia.Controls
Assembly
Avalonia.Controls.dll

A drop-down list control.

[TemplatePart("PART_Popup", typeof(Popup), IsRequired = true)]
[PseudoClasses(new string[] { ":dropdownopen", ":pressed" })]
public class ComboBox : SelectingItemsControl, INotifyPropertyChanged, IDataContextProvider, ILogical, IThemeVariantHost, IResourceHost, IResourceNode, IStyleHost, ISetLogicalParent, ISetInheritanceParent, ISupportInitialize, IStyleable, INamed, IInputElement, IDataTemplateHost, ISetterValue, IChildIndexProvider
Inheritance
ComboBox
Implements
Inherited Members
Extension Methods

Constructors

ComboBox()

public ComboBox()

Fields

HorizontalContentAlignmentProperty

Defines the HorizontalContentAlignment property.

public static readonly StyledProperty<HorizontalAlignment> HorizontalContentAlignmentProperty

Field Value

StyledProperty<HorizontalAlignment>

IsDropDownOpenProperty

Defines the IsDropDownOpen property.

public static readonly StyledProperty<bool> IsDropDownOpenProperty

Field Value

StyledProperty<bool>

MaxDropDownHeightProperty

Defines the MaxDropDownHeight property.

public static readonly StyledProperty<double> MaxDropDownHeightProperty

Field Value

StyledProperty<double>

PlaceholderForegroundProperty

Defines the PlaceholderForeground property.

public static readonly StyledProperty<IBrush?> PlaceholderForegroundProperty

Field Value

StyledProperty<IBrush>

PlaceholderTextProperty

Defines the PlaceholderText property.

public static readonly StyledProperty<string?> PlaceholderTextProperty

Field Value

StyledProperty<string>

SelectionBoxItemProperty

Defines the SelectionBoxItem property.

public static readonly DirectProperty<ComboBox, object?> SelectionBoxItemProperty

Field Value

DirectProperty<ComboBox, object>

SelectionBoxItemTemplateProperty

Defines the SelectionBoxItemTemplate property.

public static readonly StyledProperty<IDataTemplate?> SelectionBoxItemTemplateProperty

Field Value

StyledProperty<IDataTemplate>

VerticalContentAlignmentProperty

Defines the VerticalContentAlignment property.

public static readonly StyledProperty<VerticalAlignment> VerticalContentAlignmentProperty

Field Value

StyledProperty<VerticalAlignment>

Properties

HorizontalContentAlignment

Gets or sets the horizontal alignment of the content within the control.

public HorizontalAlignment HorizontalContentAlignment { get; set; }

Property Value

HorizontalAlignment

IsDropDownOpen

Gets or sets a value indicating whether the dropdown is currently open.

public bool IsDropDownOpen { get; set; }

Property Value

bool

MaxDropDownHeight

Gets or sets the maximum height for the dropdown list.

public double MaxDropDownHeight { get; set; }

Property Value

double

PlaceholderForeground

Gets or sets the Brush that renders the placeholder text.

public IBrush? PlaceholderForeground { get; set; }

Property Value

IBrush

PlaceholderText

Gets or sets the PlaceHolder text.

public string? PlaceholderText { get; set; }

Property Value

string

SelectionBoxItem

Gets or sets the item to display as the control's content.

public object? SelectionBoxItem { get; protected set; }

Property Value

object

SelectionBoxItemTemplate

Gets or sets the DataTemplate used to display the selected item. This has a higher priority than ItemTemplate if set.

[InheritDataTypeFromItems("ItemsSource")]
public IDataTemplate? SelectionBoxItemTemplate { get; set; }

Property Value

IDataTemplate

VerticalContentAlignment

Gets or sets the vertical alignment of the content within the control.

public VerticalAlignment VerticalContentAlignment { get; set; }

Property Value

VerticalAlignment

Methods

Clear()

Clears the selection

public void Clear()

CreateContainerForItemOverride(object?, int, object?)

Creates or a container that can be used to display an item.

protected override Control CreateContainerForItemOverride(object? item, int index, object? recycleKey)

Parameters

item object
index int
recycleKey object

Returns

Control

InvalidateMirrorTransform()

Computes the HasMirrorTransform value according to the FlowDirection and BypassFlowDirectionPolicies

protected override void InvalidateMirrorTransform()

NeedsContainerOverride(object?, int, out object?)

Determines whether the specified item can be its own container.

protected override bool NeedsContainerOverride(object? item, int index, out object? recycleKey)

Parameters

item object

The item to check.

index int

The index of the item.

recycleKey object

When the method returns, contains a key that can be used to locate a previously recycled container of the correct type, or null if the item cannot be recycled. If the item is its own container then by definition it cannot be recycled, so recycleKey shoud be set to null.

Returns

bool

true if the item needs a container; otherwise false if the item can itself be used as a container.

OnApplyTemplate(TemplateAppliedEventArgs)

Called when the control's template is applied. In simple terms, this means the method is called just before the control is displayed.

protected override void OnApplyTemplate(TemplateAppliedEventArgs e)

Parameters

e TemplateAppliedEventArgs

The event args.

OnAttachedToVisualTree(VisualTreeAttachmentEventArgs)

Called when the control is added to a rooted visual tree.

protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)

Parameters

e VisualTreeAttachmentEventArgs

The event args.

OnCreateAutomationPeer()

Returns a new, type-specific AutomationPeer implementation for the control.

protected override AutomationPeer OnCreateAutomationPeer()

Returns

AutomationPeer

The type-specific AutomationPeer implementation.

OnKeyDown(KeyEventArgs)

Handles directional navigation within the ItemsControl.

protected override void OnKeyDown(KeyEventArgs e)

Parameters

e KeyEventArgs

The key events.

OnPointerPressed(PointerPressedEventArgs)

Called before the PointerPressed event occurs.

protected override void OnPointerPressed(PointerPressedEventArgs e)

Parameters

e PointerPressedEventArgs

The event args.

OnPointerReleased(PointerReleasedEventArgs)

Called before the PointerReleased event occurs.

protected override void OnPointerReleased(PointerReleasedEventArgs e)

Parameters

e PointerReleasedEventArgs

The event args.

OnPointerWheelChanged(PointerWheelEventArgs)

Called before the PointerWheelChanged event occurs.

protected override void OnPointerWheelChanged(PointerWheelEventArgs e)

Parameters

e PointerWheelEventArgs

The event args.

OnPropertyChanged(AvaloniaPropertyChangedEventArgs)

Called when a avalonia property changes on the object.

protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)

Parameters

change AvaloniaPropertyChangedEventArgs

The property change details.

Events

DropDownClosed

Occurs after the drop-down (popup) list of the ComboBox closes.

public event EventHandler? DropDownClosed

Event Type

EventHandler

DropDownOpened

Occurs after the drop-down (popup) list of the ComboBox opens.

public event EventHandler? DropDownOpened

Event Type

EventHandler