ListBox<T> displays a scrollable list of items and supports selection/focus interaction.
Items are data values. By default, the list resolves a DataTemplate<T> from the environment (DataTemplates) to render each item.
You can override this per instance via ItemTemplate.
new ListBox<string>()
.Items(["First", "Second"]);
ListBox<T> is a single-selection control (SelectedIndex).
Keyboard:
Up / Down: move selectionPageUp / PageDown: jump by viewport heightHome / End: first/last itemMouse:
ListBox<T> is IScrollable, so it integrates with ScrollViewer scrollbars. Internally, the selection drives the
vertical offset to keep the selected item visible.
using XenoAtom.Terminal.UI.Templating;
new ListBox<string>()
.Items(["First", "Second"])
.ItemTemplate(new DataTemplate<string>(
Display: static (DataTemplateValue<string> value, in DataTemplateContext _) =>
new HStack(Symbols.ArrowRight, new TextBlock(() => value.GetValue())).Spacing(1),
Editor: null));
HorizontalAlignment = Align.Stretch, VerticalAlignment = Align.StretchListBoxStyle controls:
HorizontalAlignment = Align.Stretch, VerticalAlignment = Align.StretchListBoxStyle controls selection/hover colors and spacing.