Why a WPF ScrollViewer Does Not Scroll and How to Fix It

A ScrollViewer in a vertical StackPanel does not scroll because the StackPanel never constrains its height. Covers the cause and the Grid and DockPanel fixes.

Overview

The WPF ScrollViewer shows scrollbars and enables scrolling when its content is larger than the available viewport.
When a ScrollViewer is placed inside a StackPanel, however, the scrollbars never appear and the content keeps growing downward regardless of how many items it holds.
This article explains that the behavior comes from how the layout system measures elements, and it organizes the container-based fixes along with the criteria for choosing between them.


Prerequisites / Environment

The tables in this article were measured in the environment above.
Each caption states how its table was measured.
The following points were confirmed in that environment:


Problem

Placing a ScrollViewer inside a vertical StackPanel and filling it with many items often results in no scrollbar; the content extends past the visible area instead.

<StackPanel>
    <TextBlock Text="Header" />
    <ScrollViewer VerticalScrollBarVisibility="Auto">
        <StackPanel>
            <!-- many items -->
        </StackPanel>
    </ScrollViewer>
</StackPanel>

Even though VerticalScrollBarVisibility="Auto" is set, the ScrollViewer expands to the full height of its content and no scrollbar is shown.

Two regions of identical height showing the same 12 items. The one placed inside a StackPanel has no scrollbar and is cut off at the seventh item, while the one in a Grid star row shows a scrollbar.
The same header and 12 items rendered inside regions of identical height. On the left the ScrollViewer sits inside a StackPanel: no scrollbar appears and the content is clipped at the bottom of the region. On the right it sits in a * row of a Grid, so a scrollbar appears and the remaining items are reachable.

Cause / Background

The cause lies in the available size that the StackPanel passes to its children during measurement.
In its stacking direction, which is height for a vertical panel, a StackPanel measures each child with an infinite available size.
The official documentation notes that a StackPanel does not constrain its children in the direction it stacks.

A ScrollViewer shows a scrollbar only when its content is larger than the height it is given.
When the StackPanel passes an infinite height, the ScrollViewer requests exactly the height needed to fit all of its content, so no overflow occurs.
No scrollbar appears, and the ScrollViewer itself grows to the full height of its content.

The root of the problem is therefore not the ScrollViewer but the surrounding StackPanel, which never constrains the height.


The difference can be confirmed by changing only the parent layout and reading the heights off the ScrollViewer.

parent layout Extent Viewport Scrollable scrollbar
inside StackPanel 800 800 0 Collapsed
inside Grid 800 200 600 Visible
inside DockPanel (LastChildFill) 800 200 600 Visible
StackPanel + explicit Height 800 200 600 Visible
StackPanel + MaxHeight 800 200 600 Visible

Measured on .NET 10 / Windows 11 with a ScrollViewer holding 40 rows of 20px each (800px total) inside a parent constrained to 200px. Nothing differs between the rows except the parent layout.

Inside the StackPanel, ViewportHeight equals ExtentHeight at 800. Although the parent is constrained to 200px, the ScrollViewer still claims the height its full content needs.
ScrollableHeight is therefore 0 and the scrollbar stays Collapsed.

With a Grid or a DockPanel, ViewportHeight settles at 200 and the remaining 600 becomes ScrollableHeight.
As the last row shows, a StackPanel produces the same result once the ScrollViewer is given an explicit height. What matters is that a constraint reaches it.


Solution

Place the ScrollViewer in a container that constrains its height.
Specifically, put it in a Grid row sized with * (star), let a DockPanel fit it into the remaining space, or give it an explicit Height or MaxHeight.
A finite height is then passed to the ScrollViewer, and a scrollbar appears once the content exceeds that height.


Implementation

Place it in a star-sized Grid row

Split the Grid into a fixed-size row and a * row that fills the remaining space, and put the scrollable ScrollViewer in the * row.

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <TextBlock Grid.Row="0" Text="Header" />

    <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
        <StackPanel>
            <!-- many items -->
        </StackPanel>
    </ScrollViewer>
</Grid>

The * row receives the parent’s remaining height, so the ScrollViewer is given a finite height.
When the content exceeds that height, the scrollbar appears automatically.

Fit it into the remaining space with a DockPanel

A DockPanel expands its last child into the remaining area through LastChildFill, which is enabled by default.
Dock the header to the top and place the ScrollViewer as the last child.

<DockPanel>
    <TextBlock DockPanel.Dock="Top" Text="Header" />

    <ScrollViewer VerticalScrollBarVisibility="Auto">
        <StackPanel>
            <!-- many items -->
        </StackPanel>
    </ScrollViewer>
</DockPanel>

The last child without a DockPanel.Dock value fills the remaining area, so the height of the ScrollViewer is constrained.


Notes

configuration ListBoxItem realized CanContentScroll (value source)
ListBox Height=180 10 True (DefaultStyle)
ScrollViewer.CanContentScroll=False 2,000 False (Local)
VirtualizingPanel.IsVirtualizing=False 2,000 True (DefaultStyle)
CollectionView.GroupDescriptions only, no GroupStyle 10 True (DefaultStyle)
CollectionView.GroupDescriptions + GroupStyle 2,000 False (TemplateTrigger)
inside an outer ScrollViewer (Height=180) 2,000 True (DefaultStyle)
inside a StackPanel (Height=180) 2,000 True (DefaultStyle)

Measured on .NET 10 / Windows 11 by showing a ListBox with 2,000 items under each condition and counting the realized ListBoxItems. The outer ScrollViewer and StackPanel are 180 high; the ListBox itself has no height in those rows.


Alternatives / Comparison

Container Scrolling behavior Suited for
StackPanel (vertical) Does not constrain height, so the ScrollViewer does not scroll unless given an explicit Height or MaxHeight Short content that needs no scrolling
Grid with a * row Passes the remaining height; scrolls when content overflows Screens that separate headers or footers from a variable area
DockPanel (LastChildFill) Fits into the remaining area; scrolls when content overflows Screens combining edge-docked elements with a main area
Explicit Height / MaxHeight Scrolls once the specified height is exceeded A partial list with a fixed height cap

Summary

A StackPanel passes an infinite height to its children in the stacking direction, so a ScrollViewer inside it cannot detect overflow and does not scroll.
The root of the problem is the surrounding container that fails to constrain the height, not the ScrollViewer itself.

The selection criteria are as follows.

In every case, the key is a layout that passes a finite height to the ScrollViewer.