Table of Contents

Class ListBox

Namespace
PluginUI
Assembly
PluginUI.dll

Virtualized list of items (presets, files, samples...): only visible rows are drawn, so lists of any length cost the same per frame. Single or extended selection (Ctrl / Shift), keyboard navigation with type-ahead, wheel and slim scrollbar, double-click / Enter activation and optional drag reordering.

public class ListBox : Control
Inheritance
ListBox
Inherited Members

Remarks

Items accepts any IList (e.g. List<string>). After changing the list itself, call Refresh().

Constructors

ListBox()

Creates an empty list.

public ListBox()

ListBox(IList)

Creates a list over items.

public ListBox(IList items)

Parameters

items IList

Properties

AllowReorder

Lets the user reorder rows by dragging (the Items list must be writable).

public bool AllowReorder { get; set; }

Property Value

bool

Count

Number of items.

public int Count { get; }

Property Value

int

DefaultSize

Natural size used when no explicit size is given.

protected override Size DefaultSize { get; }

Property Value

Size

DrawBackground

Draws the frame and background.

public bool DrawBackground { get; set; }

Property Value

bool

EmptyText

Text shown when the list is empty.

public string? EmptyText { get; set; }

Property Value

string

ItemHeight

Row height in DIPs.

public float ItemHeight { get; set; }

Property Value

float

ItemRenderer

Custom row renderer (replaces the default text row; selection/hover backgrounds are still drawn).

[Browsable(false)]
public Action<DrawingContext, Rect, object, ListItemState>? ItemRenderer { get; set; }

Property Value

Action<DrawingContext, Rect, object, ListItemState>

ItemText

Text of an item (default: ToString()).

[Browsable(false)]
public Func<object, string>? ItemText { get; set; }

Property Value

Func<object, string>

Items

Items (any list; strings are shown as is).

public IList? Items { get; set; }

Property Value

IList

MultiSelect

Allows several selected rows (Ctrl+click, Shift+click, Shift+arrows, Ctrl+A).

public bool MultiSelect { get; set; }

Property Value

bool

SelectedIndex

First selected index (-1 = none); setting it selects only that row and scrolls it into view.

public int SelectedIndex { get; set; }

Property Value

int

SelectedIndices

Selected indices in ascending order.

public IReadOnlyCollection<int> SelectedIndices { get; }

Property Value

IReadOnlyCollection<int>

SelectedItem

First selected item.

public object? SelectedItem { get; }

Property Value

object

Striped

Draws alternate row backgrounds.

public bool Striped { get; set; }

Property Value

bool

Methods

LayoutParts(VectorStyle, out Rect, out Rect, out Rect)

Splits the bounds into label (top), widget and value (bottom) areas according to the style. Override to change the arrangement (e.g. label on the left for sliders).

protected override void LayoutParts(VectorStyle style, out Rect label, out Rect widget, out Rect value)

Parameters

style VectorStyle
label Rect
widget Rect
value Rect

OnCaptureLost()

The mouse capture was lost without a button release.

protected override void OnCaptureLost()

OnDragLeave()

Internal drag left this element.

protected override void OnDragLeave()

OnDragOver(DragEventArgs)

Internal drag over this element: set Accept to accept.

protected override void OnDragOver(DragEventArgs e)

Parameters

e DragEventArgs

OnDrop(DragEventArgs)

Internal drop on this element.

protected override void OnDrop(DragEventArgs e)

Parameters

e DragEventArgs

OnKeyDown(KeyEventArgs)

Key pressed while focused (bubbles to parents).

protected override void OnKeyDown(KeyEventArgs e)

Parameters

e KeyEventArgs

OnMouseDown(MouseEventArgs)

Mouse button pressed over the element (or captured).

protected override void OnMouseDown(MouseEventArgs e)

Parameters

e MouseEventArgs

OnMouseLeave()

The mouse left the element.

protected override void OnMouseLeave()

OnMouseMove(MouseEventArgs)

Mouse moved over the element (or captured).

protected override void OnMouseMove(MouseEventArgs e)

Parameters

e MouseEventArgs

OnMouseUp(MouseEventArgs)

Mouse button released.

protected override void OnMouseUp(MouseEventArgs e)

Parameters

e MouseEventArgs

OnMouseWheel(MouseEventArgs)

Mouse wheel over the element.

protected override void OnMouseWheel(MouseEventArgs e)

Parameters

e MouseEventArgs

OnRenderOverlay(DrawingContext)

Draws the keyboard focus ring.

protected override void OnRenderOverlay(DrawingContext dc)

Parameters

dc DrawingContext

Refresh()

Re-reads the list after it changed (clamps the selection and the scroll position).

public void Refresh()

RenderVector(DrawingContext, Rect, VectorStyle)

Vector rendering of the widget area.

protected override void RenderVector(DrawingContext dc, Rect widget, VectorStyle style)

Parameters

dc DrawingContext
widget Rect
style VectorStyle

ScrollIntoView(int)

Scrolls so that the row is visible.

public void ScrollIntoView(int index)

Parameters

index int

TextOf(object?)

Text displayed for an item.

protected string TextOf(object? item)

Parameters

item object

Returns

string

Events

ItemActivated

Raised on double-click or Enter.

public event Action<ListBox, int>? ItemActivated

Event Type

Action<ListBox, int>

ItemMoved

Raised after a drag reorder moved an item (from, to).

public event Action<ListBox, int, int>? ItemMoved

Event Type

Action<ListBox, int, int>

SelectionChanged

Raised when the selection changes.

public event Action<ListBox>? SelectionChanged

Event Type

Action<ListBox>