# Lists and repeated content

Show four trails and report which one the user selects. A ToolKit `ListView` provides a scrollable surface and selection visuals while each row supplies its own content.

<div class="docs-demo-layout">

```csharp
using Xui.Core.UI;
using Xui.Core.UI.Layout;
using Xui.ToolKit.UI.Design;
using Xui.ToolKit.UI.Widgets;

public sealed class ListExample : Border
{
    public ListExample()
    {
        var selected = new Label
        {
            Text = "Choose a trail.",
            FontFamily = "Inter",
            FontSize = 18,
            Margin = 16
        };
        string[] names = ["River walk", "Pine ridge", "Lookout point", "Lake circuit"];
        var rows = new View[names.Length];
        for (var i = 0; i < names.Length; i++)
            rows[i] = new ListViewItem
            {
                ItemContent = new Label
                {
                    Text = names[i],
                    FontFamily = "Inter",
                    FontSize = 18,
                    Margin = 12
                }
            };
        var list = new ListView
        {
            Content = rows,
            SelectionChanged = index => selected.Text = names[index]
        };
        var grid = new Grid
        {
            TemplateColumns = [Grid.TrackSize.Fr(1)],
            TemplateRows = [Grid.TrackSize.Px(72), Grid.TrackSize.Fr(1)]
        };
        grid.Add(selected);
        grid.Add(list);
        Content = new DesignSystemView(grid);
    }
}
```

<figure class="docs-demo" data-demo-url="../../../wasm/?embed=1&amp;demo=controls/lists">
<div class="docs-demo-stage">
<img src="controls-lists.svg" width="400" height="600" alt="Lists and repeated content: initial rendered view" />
<button type="button" class="docs-demo-start" hidden><span class="docs-demo-pill">Start demo</span></button>
</div>
<div class="docs-demo-actions">
<button type="button" class="docs-demo-close" hidden>Close demo</button>
<span class="docs-demo-status" role="status" aria-live="polite"></span>
</div>
<figcaption>Lists and repeated content · <a href="controls-lists.cs">C# source</a> · <a href="controls-lists.svg">SVG</a> · <a href="../../../wasm/?embed=1&amp;demo=controls/lists">Open demo</a></figcaption>
</figure>

</div>


## Build rows from data

The example separates the names array from its row views. Each `ListViewItem` hosts a label through `ItemContent`. The list receives those rows through its init-only `Content` property, and `SelectionChanged` updates the heading using the selected index.

A Grid reserves a 72-unit heading row and gives the rest of the available height to the list. That bounded second row matters: the list contains its own `ScrollView`, so it needs a viewport rather than unlimited vertical space.

`DesignSystemView` supplies the selected and hover colors, item shape, and spacing. Keep the list and its items inside the provider.

## Treat selection as application state

`SelectedIndex` uses `-1` for no selection. A user selection invokes `SelectionChanged`; assigning the property programmatically redraws the list but does not invoke that callback. Update your model explicitly when code selects an item.

The current item implementation selects during pointer Down in the tunneling phase. Selection can therefore change at the beginning of a gesture that becomes scrolling. Do not use this callback for an irreversible action such as deleting a record or sending a payment. Let selection preview an item and use a separate explicit action to commit work.

This list does not provide complete keyboard selection behavior by default. Evaluate keyboard and accessibility requirements separately.

## Keep collection size under control

The list eagerly creates and measures its child views. It does not virtualize rows, recycle containers, or provide an observable collection binding layer. Four trails are inexpensive; thousands of rich rows require a different strategy.

For a changing small collection, rebuild the list content at an intentional boundary and restore selection using a stable data ID. Do not assume an old numeric index still names the same item after sorting or deleting. For a large collection, add paging or a virtualizing container and measure the result.

Try adding enough rows to make the example scroll, then select a row near the bottom. Check that the selected record, the visual highlight, and your application state still agree after any data update.
