Skip to content

FIX: ScrollViewer ignores padding when measuring children - #20025

Closed
martinflorek wants to merge 4 commits into
AvaloniaUI:mainfrom
martinflorek:fix/scrollviewer_ignores_padding_when_measuring_children
Closed

martinflorek wants to merge 4 commits into
AvaloniaUI:mainfrom
martinflorek:fix/scrollviewer_ignores_padding_when_measuring_children

Conversation

@martinflorek

Copy link
Copy Markdown

What does the pull request do?

ScrollViewer now honors padding when measuring its children. Should fix #17158. The bug looks to be in the ScrollContentPresenter, not the ScrollViewer itself.

I am not 100% sure if this is all that is needed to fix the ScrollViewer with padding scrolling issue. This is my first look at Avalonia source code.

What is the current behavior?

Currently the ScrollViewer ignores its padding when measuring its children. And in case when it cannot scroll horizontally or vertically, it is unable to scroll to the very end, see #17158

What is the updated/expected behavior with this PR?

ScrollViewer should use its padding to limit the available size when measuring its children.

Checklist

Breaking changes

Probably none, because the current behaviour is broken and ScrollViewer cannot be scrolled to the very end.

Fixed issues

Fixes #17158
Fixes #12182

@maxkatz6 maxkatz6 added bug backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch labels Nov 10, 2025
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.0.999-cibuild0059920-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@cla-avalonia

cla-avalonia commented Nov 10, 2025 •

Copy link
Copy Markdown
  • All contributors have signed the CLA.

@martinflorek

Copy link
Copy Markdown
Author

@cla-avalonia agree

@martinflorek

Copy link
Copy Markdown
Author

I tested the build 12.0.999-cibuild0059920-alpha and is not fully fixed. Measuring is now good, but there is still problem with the scrolling to the very end. I will dig deeper into this and update the PR.

@martinflorek

Copy link
Copy Markdown
Author

The problem in ScrollContentPresenter is just one part. There looks to be another problem with the ScrollViewer itself, where it incorrectly computes its Extent and Viewport properties without Padding, and may even more.

I am unable to create a ScrollViewer unit test, that will trigger all the measuring/layout code down to ScrollContentPresenter, so I will get Extent, Viewport and child size computed like in real application. Can someone help me with this please?

Another issue I started thinking about is: what does a padding in a scrolling view mean in general? Personally I want the "padding to scroll with the content", but some will probably expect a fixed padding like in other views i.e., fixed inset "frame" around the content, that scrolls within it. Maybe a scrolling view should not have a padding property at all? @timunie @trashhacker ?

@timunie

timunie commented Nov 12, 2025

Copy link
Copy Markdown
Collaborator

The team will review the PR once we have enough capacity for it.

About the last question: would be interesting to evaluate what other frameworks like WPF do about the padding.

@kekekeks

Copy link
Copy Markdown
Member

Note that there are various problems with Margin handling too.
e. g.

<ScrollViewer>
                <StackPanel Margin="0 400" Spacing="400">
                        <TextBox>Tab between boxes</TextBox>
                        <TextBox>Tab between boxes</TextBox>
                        <TextBox>Tab between boxes</TextBox>
                        <TextBox>Tab between boxes</TextBox>
                </StackPanel>
        </ScrollViewer>

will break BringIntoView.

@MrJul MrJul removed the backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch label Jun 18, 2026
@MrJul MrJul added backport-candidate-12.0.x backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch and removed backport-candidate-12.0.x labels Jul 3, 2026
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.2.999-cibuild0067831-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul

MrJul commented Jul 28, 2026

Copy link
Copy Markdown
Member

The fix in this PR doesn't handle the padding correctly in all cases.
Closing in favor of #21872.

@MrJul MrJul closed this Jul 28, 2026
@MrJul MrJul removed the backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch label Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ScrollViewer not scrolling to end with bottom padding... ScrollViewer with Padding cut content and not scrollable to end

7 participants