Docs / UI

Glossary: ListBox Style

The properties, methods and events of ListBox, in alphabetical order.

Color legend plain property dependency property method event

A scrollable list of rows with single or multiple selection. A row can be a text, any element, or an object of an ItemsSource, and long lists can be virtualized so only the rows in view have elements.

ListBox derives from BaseElement and has its members too. The lists and menus page shows it in context, with code and screenshots.

Names are colored by what they are: a plain property, a method, an event or a dependency property, which a style, a binding or an animation can set.

Properties

AlternativeItemColor 🠆

Color · The background of the odd unselected rows while UseDualColors is set. (240, 240, 245) unless set (DefaultSettings.DefaultListBoxAlternativeItemColor).

ContentHeight 🠆

int · Read-only. The height of all the shown rows together, in units (Count times ItemHeight in Fixed mode).

ContentWidth 🠆

int · Read-only. The width of the widest row content, in units (in Fixed mode the widest seen since the rows were cleared).

Count 🠆

int · Read-only. The number of rows, in every virtualization mode.

GeneralMouseCursorsSet 🠆

MouseCursorsSet · Static. The cursors of every element of this style type; null (the default) falls back to DefaultMouseCursorsSet.

GeneralStyle 🠆

ListBoxStyle · Static. The style of every element of this style type. It starts as a copy of the framework defaults; changing one of its properties updates every such element, a property it leaves unset takes its default.

HoverItemColor 🠆

Color? · The background of the row under the mouse. When null the row keeps its normal or selected color. (220, 232, 245) unless set (DefaultSettings.DefaultListBoxHoverItemColor).

ItemHeight 🠆

int · The height of every row in Fixed mode, in units. 24 unless set (DefaultSettings.DefaultListBoxItemHeight); Fixed mode has no effect while it is 0 or less.

Items 🠆

IReadOnlyList<ListBoxItem> · Read-only. The rows that have an element, in order: every row in None mode, the rows around the view and the primary selected row in Fixed mode. A live view, don’t keep it across changes.

ItemsSource 🠆

IEnumerable · The objects to show, one row each. A BindableCollection<T> is followed.

ItemsTemplate 🠆

IItemsTemplate · Makes the element of each ItemsSource object; a label with the object’s text when none is set. Changing it builds the rows again.

MouseCursorsSet 🠆

MouseCursorsSet · Read-only. The cursors the element shows: its override, else the set given to the control it is a part of, else its type’s general set, else DefaultMouseCursorsSet.

MouseCursorsSetOverride 🠆

MouseCursorsSet · The cursors of this element only, passed on to its parts that have none of their own.

NormalItemColor 🠆

Color · The background of an unselected row (of the even rows with UseDualColors). Transparent unless set, so the rows lie on the list’s background.

PressedItemColor 🠆

Color? · The background of a row while the left button is pressed on it. When null it doesn’t change. (160, 190, 225) unless set (DefaultSettings.DefaultListBoxPressedItemColor).

RowsPerPage 🠆

int · Read-only. The number of rows that fit the view, at least one: the view’s height divided by ItemHeight in Fixed mode, by the average row height otherwise.

ScrollableContainerStyle 🠆

ScrollableContainerStyle · The style of the scrollable container around the rows, for example its scroll bars and their thickness. Unless set, the container has its own defaults: a scroll bar wherever the rows need one, 12 units thick.

SelectedIndex 🠆

int · The index of the primary selected row, -1 when nothing is selected. Setting it selects that row (the value is clamped to the rows); a negative value clears the selection.

SelectedIndices 🠆

IReadOnlyList<int> · Read-only. The indices of all selected rows, with an element or not.

SelectedItem 🠆

ListBoxItem · The primary selected row, null when nothing is selected. Setting it selects that row; null clears the selection.

SelectedItemColor 🠆

Color? · The background of a selected row. When null a selected row keeps the color it had. (190, 215, 240) unless set (DefaultSettings.DefaultListBoxSelectedItemColor).

SelectedItems 🠆

IReadOnlyList<ListBoxItem> · Read-only. The selected rows that have an element (see Items).

SelectedSources 🠆

IReadOnlyList<object> · Read-only. The source objects of all selected rows, null for rows added as elements or text.

SelectionMode 🠆

ListBoxSelectionMode · Whether one row or several rows can be selected. Single by default.

StyleOverride 🠆

ListBoxStyle · A style for this element only, applied over the general style. Setting it to null takes its values back out.

UseDualColors 🠆

bool · Alternates the background of unselected rows: NormalItemColor for even rows, AlternativeItemColor for odd ones, counted without the separators (a separator row lies on the normal color).

VirtualizationMode 🠆

ListBoxVirtualizationMode · Whether every row has an element (None, the default) or only the rows around the view (Fixed).

Methods

ListBox() 🠆

ListBox(string name = null) · Creates a list box. The name is used by GetElementByName.

Parameter Type Description
name string The element’s Name, which GetElementByName finds it by. Default: null.

AddItem() 🠆

AddItem(BaseElement item) · Adds a row at the end. A ListBoxItem is the row itself, any other element is shown in a row the list makes.

Parameter Type Description
item BaseElement The element to add.

AddItemAt() 🠆

AddItemAt(BaseElement item, int index) · Inserts a row at the index (0 to Count); another index is ignored.

Parameter Type Description
item BaseElement The element to insert.
index int The position to insert it at: 0 for the first, the number of items for the end.

AddItemsRange() 🠆

AddItemsRange(IEnumerable<BaseElement> items) · Adds a row per element at the end, in one batch (the rows are indexed and laid out once).

Parameter Type Description
items IEnumerable<BaseElement> The elements to add, in order.

AddItemsRangeAt() 🠆

AddItemsRangeAt(IEnumerable<BaseElement> items, int index) · Inserts a row per element at the index, in one batch.

Parameter Type Description
items IEnumerable<BaseElement> The elements to insert, in order.
index int The position of the first one: 0 for the first, the number of items for the end.

AddTextItem() 🠆

AddTextItem(string text) · Adds a text row. Does nothing while an ItemsSource is set.

Parameter Type Description
text string The text of the row.

AddTextItems() 🠆

AddTextItems(IEnumerable<string> texts) · Adds a text row per string, in one batch. Does nothing while an ItemsSource is set.

Parameter Type Description
texts IEnumerable<string> The texts, one row per string.

ClearItems() 🠆

ClearItems() · Removes every row.

Deselect() 🠆

Deselect(BaseElement item) · Deselects the row of the item, as DeselectAt does.

Parameter Type Description
item BaseElement The element whose row is deselected.

DeselectAll() 🠆

DeselectAll() · Deselects every row.

DeselectAt() 🠆

DeselectAt(int index) · Deselects the row at the index. If it was the primary row, the first row that is still selected becomes the primary one.

Parameter Type Description
index int The index of the row to deselect.

MoveSelection() 🠆

MoveSelection(int delta) · Moves the selection by delta rows (clamped to the list, separators and collapsed rows passed over) and scrolls it into view. With no selection it selects the first row (delta above 0) or the last.

Parameter Type Description
delta int How many rows to move: negative moves up, positive down.

RemoveItem() 🠆

RemoveItem(BaseElement item) · Removes the row of the item (the row itself or the element shown in it).

Parameter Type Description
item BaseElement The element to take out.

RemoveItemAt() 🠆

RemoveItemAt(int index) · Removes the row at the index.

Parameter Type Description
index int The index of the item to take out.

RemoveItemsRangeAt() 🠆

RemoveItemsRangeAt(int index, int count) · Removes count rows from the index on (as many as there are).

Parameter Type Description
index int The index of the first item to take out.
count int The number of items to take out.

ScrollIntoView() 🠆

ScrollIntoView(int index) · Scrolls the list so the row at the index is entirely in view. Needs the list laid out; nothing happens for a row that is in view already.

Parameter Type Description
index int The index of the row to bring into view.

Select() 🠆

Select(BaseElement item) · Selects the row of the item (the row itself or the element shown in it), as SelectAt does.

Parameter Type Description
item BaseElement The element whose row is selected.

SelectAll() 🠆

SelectAll() · Selects every row except separators; the last one becomes the primary row. In Single mode it selects the first selectable row, and only when nothing is selected.

SelectAt() 🠆

SelectAt(int index) · Makes the row at the index the selected row; the other rows are deselected, also in Multiple mode. An index out of range is ignored.

Parameter Type Description
index int The index of the row to select.

SelectNext() 🠆

SelectNext() · Selects the next row (separators and collapsed rows passed over) and scrolls it into view. Does nothing without a selection.

SelectPrevious() 🠆

SelectPrevious() · Selects the previous row (separators and collapsed rows passed over) and scrolls it into view. Does nothing without a selection.

SelectSource() 🠆

SelectSource(object source) · Selects the row whose Source is the object. Nothing happens when there is none.

Parameter Type Description
source object The ItemsSource object whose row is selected.

Events

OnItemSelect 🠆

(BaseElement sender, ListBoxItem item) · The primary selection is set, by the user or from code. item is null when nothing is selected any more.

Parameter Type Description
sender BaseElement The list box, or the combo box whose drop-down list it is.
item ListBoxItem The primary selected row, or null when nothing is selected any more.

OnItemsSelect 🠆

(BaseElement sender, IReadOnlyList<ListBoxItem> items) · The set of selected rows changes. items is SelectedItems, the selected rows that have an element.

Parameter Type Description
sender BaseElement The element that raised the event.
items IReadOnlyList<ListBoxItem> The selected rows that have an element (SelectedItems).