Skip to content

ListBox class

A scrollable list control with item selection.

Guide: C# Markup reference: Listbox

public class ListBox : ScrollableItemsBase, IIndexedSelector, IMultiSelector
name description
ListBox() Initializes a new instance of the ListBox class.
HorizontalScroll { get; set; } Gets or sets the horizontal scroll mode, Auto by default, so items wider than the viewport scroll horizontally.
ItemHeight { get; set; } Gets or sets the height of each list item.
ItemPadding { get; set; } Gets or sets the padding around each item’s text.
ItemsSource { get; set; } Gets or sets the items source.
ItemTemplate { get; set; } Gets or sets the item template; unset, the default template is used.
SelectedIndex { get; set; } Gets or sets the selected item index.
SelectedIndices { get; } Gets the selected item indices in ascending order.
SelectedItem { get; set; } Gets the currently selected item object.
SelectedItems { get; } Gets the selected items in ascending index order (read-only, bindable).
SelectedText { get; } Gets the currently selected item text.
SelectionMode { get; set; } Gets or sets the selection mode; multi-selection needs an items source that supports it (e.g. created from a typed list), otherwise the mode stays Single.
ZebraStriping { get; set; } Gets or sets whether alternating items use a second background color (zebra striping).
event SelectedIndicesChanged Occurs when the set of selected items changes (multi-select).
event SelectionChanged Occurs when the selected item changes.
ClearSelection() Clears the entire selection.
IsSelected(…) Returns whether the item at index is selected.
ScrollIntoView(…)
SelectAll() Selects every item (multi-selection modes only; no-op otherwise).
SelectRange(…) Selects the inclusive range [start, end], replacing the current selection (multi only).
TryGetContainer(…) Gets the container currently showing the item at index. False when that item is not realized, which is the normal state of one scrolled out of view.
TryGetItemBounds(…) The item’s rectangle in this control’s coordinate space, spanning the item’s full width. False when the index is out of range or the list cannot say where the item sits, which a variable-height list answers for an item it has not measured yet. The rectangle can fall outside the viewport; intersect it with Bounds for the visible part.
TryGetItemIndexAt(…) Attempts to find the item index at the specified position in this control’s coordinates. (2 methods)
static readonly HorizontalScrollProperty
static readonly ItemHeightProperty Gets or sets the height of each list item.
static readonly ItemPaddingProperty Gets or sets the padding around each item’s text.
static readonly SelectedIndexProperty
static readonly SelectedItemProperty
static readonly SelectedItemsProperty
static readonly SelectionModeProperty
static readonly ZebraStripingProperty