Table of Contents

Class ListBox

Namespace
Avalonia.Controls
Assembly
Avalonia.Controls.dll

An ItemsControl in which individual items can be selected.

[TemplatePart("PART_ScrollViewer", typeof(IScrollable))]
public class ListBox : SelectingItemsControl, INotifyPropertyChanged, IDataContextProvider, ILogical, IThemeVariantHost, IResourceHost, IResourceNode, IStyleHost, ISetLogicalParent, ISetInheritanceParent, ISupportInitialize, IStyleable, INamed, IInputElement, IDataTemplateHost, ISetterValue, IChildIndexProvider
Inheritance
ListBox
Implements
Inherited Members
Extension Methods

Constructors

ListBox()

public ListBox()

Fields

ScrollProperty

Defines the Scroll property.

public static readonly DirectProperty<ListBox, IScrollable?> ScrollProperty

Field Value

DirectProperty<ListBox, IScrollable>

SelectedItemsProperty

Defines the SelectedItems property.

public static readonly DirectProperty<SelectingItemsControl, IList?> SelectedItemsProperty

Field Value

DirectProperty<SelectingItemsControl, IList>

SelectionModeProperty

Defines the SelectionMode property.

public static readonly StyledProperty<SelectionMode> SelectionModeProperty

Field Value

StyledProperty<SelectionMode>

SelectionProperty

Defines the Selection property.

public static readonly DirectProperty<SelectingItemsControl, ISelectionModel> SelectionProperty

Field Value

DirectProperty<SelectingItemsControl, ISelectionModel>

Properties

Scroll

Gets the scroll information for the ListBox.

public IScrollable? Scroll { get; }

Property Value

IScrollable

SelectedItems

public IList? SelectedItems { get; set; }

Property Value

IList

Selection

public ISelectionModel Selection { get; set; }

Property Value

ISelectionModel

SelectionMode

Gets or sets the selection mode.

public SelectionMode SelectionMode { get; set; }

Property Value

SelectionMode

Remarks

Note that the selection mode only applies to selections made via user interaction. Multiple selections can be made programmatically regardless of the value of this property.

Methods

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

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.

OnKeyDown(KeyEventArgs)

Handles directional navigation within the ItemsControl.

protected override void OnKeyDown(KeyEventArgs e)

Parameters

e KeyEventArgs

The key events.

SelectAll()

Selects all items in the ListBox.

public void SelectAll()

UnselectAll()

Deselects all items in the ListBox.

public void UnselectAll()