Build with XuiView Markdown

Scrolling content

Let a list of field notes extend beyond the page while keeping the window itself a stable size. ScrollView clips its content and translates it as the user drags or scrolls.

using Xui.Core.Canvas;
using Xui.Core.UI;

public sealed class ScrollingExample : ScrollView
{
    public ScrollingExample()
    {
        var rows = new VerticalStack
        {
            Margin = 16
        };
        for (var index = 1; index <= 24; index++)
        {
            rows.Add(new Border { Padding = 20, Margin = 4, BackgroundColor = new Color(0xEADCFBFF), Content = new Label { Text = $"Field note {index}", FontFamily = "Inter", FontSize = 18 } });
        }

        Content = rows;
    }
}
Scrolling content: initial rendered view
Scrolling content · C# source · SVG · Open demo

Separate content size from viewport size

The stack measures the height of all 24 rows. The scroll view occupies the available viewport and measures content along its scroll direction. The difference between those dimensions is the scrollable range.

Put a scroll view in a bounded window, grid track, or custom container. A vertical stack gives its children unlimited height; putting a vertical scroll view directly inside that stack without a height constraint may give it no meaningful viewport to scroll within.

The example uses the default vertical direction. Set Direction to Horizontal for a horizontal strip or Both for a larger surface that pans in two axes. Keep your content's desired size meaningful on each scrolling axis.

Let the container own motion

ScrollView negotiates gestures with descendants, translates content, clips to the viewport by default, and draws scrollbar indicators. Avoid applying an additional translation to each row in response to the same wheel event; that would move content twice.

The current ScrollOffset includes elastic overscroll. ScrollChanged reports changes as dragging, inertia, and rebound move the content. Use it for observation or a synchronized visual, not as evidence that the offset always lies between zero and the content's maximum.

A foreground Overlay remains outside the content's scroll transform. It can hold a viewport-attached visual, but its input still participates in the scroll view's gesture negotiation.

Keep long content affordable

The example intentionally creates only a small fixed collection. A stack of 10,000 rows still has 10,000 views; scrolling does not automatically virtualize them. Use paging or a virtualizing strategy for large data sets, and measure construction and layout costs.

Nested scrolling can be useful when the axes differ. Two vertical scroll regions competing for the same drag need deliberate testing. Verify buttons within scrolling content, drag cancellation, and trackpad behavior rather than inferring the result from a static image.

Continue with Lists and repeated content when rows also need selection.