You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Scrollable list control with single selection and keyboard/mouse navigation.
Overview
ListControl displays a scrollable list of items with selection support. Users can navigate with keyboard or mouse, select items, and activate items (double-click or Enter).
Properties
Property
Type
Default
Description
Items
ObservableCollection<ListItem>
Empty
List of items to display
SelectedIndex
int
-1
Index of selected item (-1 = none)
SelectedItem
ListItem?
null
Currently selected item
MaxVisibleItems
int
10
Number of visible items
IsEnabled
bool
true
Enable/disable list
BackgroundColor
Color?
null
Background color (uses theme if null)
ForegroundColor
Color?
null
Text color (uses theme if null)
HasFocus
bool
false
Whether list has keyboard focus
Events
Event
Arguments
Description
SelectedIndexChanged
EventHandler<int>
Fired when selection index changes
SelectedItemChanged
EventHandler<ListItem?>
Fired when selected item changes
ItemActivated
EventHandler<ListItem>
Fired when item is double-clicked or Enter pressed
publicclassPerson{publicstringName{get;set;}publicintAge{get;set;}}varpeople=new[]{newPerson{Name="Alice",Age=30},newPerson{Name="Bob",Age=25},newPerson{Name="Charlie",Age=35}};varlist=newListControl{MaxVisibleItems=10};foreach(varpersoninpeople){list.Items.Add(newListItem(person.Name){Tag=person// Store custom data});}list.ItemActivated+=(sender,item)=>{varperson=item.TagasPerson;if(person!=null){windowSystem.NotificationStateService.ShowNotification("Person Details",$"{person.Name} is {person.Age} years old",NotificationSeverity.Info);}};window.AddControl(list);
Master-Detail Pattern
varlist=Controls.List().AddItem("Item 1").AddItem("Item 2").AddItem("Item 3").WithName("masterList").OnSelectionChanged((sender,index,window)=>{vardetail=window.FindControl<MarkupControl>("detailView");if(index>=0){varitem=sender.SelectedItem;detail?.SetContent(newList<string>{$"[bold yellow]{item?.Text}[/]","","Detailed information about this item...",$"Selected index: {index}"});}}).Build();window.AddControl(list);window.AddControl(Controls.Markup().AddLine("[dim]Select an item to see details[/]").WithName("detailView").Build());
Searchable List
varallItems=new[]{"Apple","Apricot","Banana","Blueberry","Cherry","Date"};varlist=Controls.List().WithHeight(10).WithName("searchableList").Build();// Initialize with all itemsforeach(variteminallItems){list.Items.Add(newListItem(item));}// Add search boxwindow.AddControl(Controls.Prompt("Search:").OnInputChanged((sender,text,window)=>{varlist=window.FindControl<ListControl>("searchableList");if(list!=null){list.Items.Clear();varfiltered=string.IsNullOrWhiteSpace(text)?allItems:allItems.Where(i =>i.Contains(text,StringComparison.OrdinalIgnoreCase));foreach(variteminfiltered){list.Items.Add(newListItem(item));}list.Invalidate();}}).Build());window.AddControl(list);
Dynamic List Updates
varlist=Controls.List().WithName("dynamicList").WithHeight(10).Build();window.AddControl(list);// Add button to add itemswindow.AddControl(Controls.Button("Add Item").OnClick((s,e,w)=>{varlist=w.FindControl<ListControl>("dynamicList");if(list!=null){varcount=list.Items.Count+1;list.Items.Add(newListItem($"Item {count}"));list.Invalidate();}}).Build());// Add button to remove selectedwindow.AddControl(Controls.Button("Remove Selected").OnClick((s,e,w)=>{varlist=w.FindControl<ListControl>("dynamicList");if(list!=null&&list.SelectedIndex>=0){list.Items.RemoveAt(list.SelectedIndex);list.Invalidate();}}).Build());
Formatted List Items
varlist=Controls.List().AddItem("[green]Available[/] - Service Running").AddItem("[yellow]Warning[/] - High CPU Usage").AddItem("[red]Error[/] - Service Stopped").AddItem("[blue]Info[/] - Update Available").WithHeight(10).Build();window.AddControl(list);
varlist=Controls.List().WithName("itemList").WithHeight(10).OnSelectionChanged((s,index,w)=>{varstatus=w.FindControl<MarkupControl>("statusBar");status?.SetContent($"Item {index+1} of {s.Items.Count}");}).Build();window.AddControl(list);window.AddControl(Controls.Label("No selection").WithName("statusBar").StickyBottom().Build());