Skip to content

Fix VirtualizingStackPanel offset when scrolling to variable-sized items - #21975

Merged
grokys merged 6 commits into
AvaloniaUI:mainfrom
zrt2399:fix_issue_21971
Aug 27, 2026
Merged

grokys merged 6 commits into
AvaloniaUI:mainfrom
zrt2399:fix_issue_21971

Conversation

@zrt2399

@zrt2399 zrt2399 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

What does the pull request do?

Fixes incorrect VirtualizingStackPanel offsets when ScrollIntoView targets an unrealized item before the current realized range and the items have variable sizes.

This can occur, for example, when reopening a ComboBox with a selected item in the middle of the list. The selected item may already appear at the top while the popup still has additional scrollable space above it.

What is the current behavior?

bugdemo

What is the updated/expected behavior with this PR?

bugdemo1

How was the solution implemented (if it's not obvious)?

GetOrEstimateElementU now accepts an isScrollIntoView parameter.

For a preceding ScrollIntoView target, it interpolates between index 0 at the panel origin and the first realized item's known position. Other callers, such as positioning a retained focused container outside the realized range, continue using the existing average-size extrapolation behavior.

Checklist

Fixed issues

Fixes #21971

@avaloniaui-bot

Copy link
Copy Markdown

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

@MrJul MrJul added bug backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Aug 14, 2026
@grokys grokys self-assigned this Aug 26, 2026

@grokys grokys left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, other than a small nit! (I can happily remove the parameter myself if you'd like)

grokys
grokys previously approved these changes Aug 26, 2026

@grokys grokys left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the parameter. LGTM now.

@grokys
grokys enabled auto-merge August 26, 2026 18:07
@MrJul

MrJul commented Aug 26, 2026

Copy link
Copy Markdown
Member

FYI, Focused_Container_Is_Positioned_Correctly_When_Scrolled_Past_Items_With_Different_Heights seems to genuinely fail on CI with these changes. I haven't looked at which is the correct behavior yet.

Change the the test to check that the element is outside of the viewport, instead of asserting its exact coordinates - that's the important part.
@grokys

grokys commented Aug 26, 2026

Copy link
Copy Markdown
Member

Looks like we had a test that was asserting exact coordinates that started failing. Tweaked the test to just check what is important: that the element is not in the viewport.

@avaloniaui-bot

Copy link
Copy Markdown

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

Azure Pipelines never queued a build for 3d81ceb.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0169P8BipcMkn44hvhpQ2UNF
@avaloniaui-bot

Copy link
Copy Markdown

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

@grokys
grokys added this pull request to the merge queue Aug 27, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 27, 2026
@grokys
grokys added this pull request to the merge queue Aug 27, 2026
Merged via the queue into AvaloniaUI:main with commit 38402fc Aug 27, 2026
10 checks passed
MrJul pushed a commit to MrJul/Avalonia that referenced this pull request Sep 2, 2026
…ems (AvaloniaUI#21975)

* Fix VirtualizingStackPanel offset when scrolling to variable-sized items

* Remove the `isScrollIntoView` parameter.

* Tweak now-failing test.

Change the the test to check that the element is outside of the viewport, instead of asserting its exact coordinates - that's the important part.

* Retrigger CI.

Azure Pipelines never queued a build for 3d81ceb.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0169P8BipcMkn44hvhpQ2UNF

---------

Co-authored-by: grokys <grokys@users.noreply.github.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
@MrJul MrJul added backported-12.1.x and removed backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ComboBox popup has an incorrect scroll offset after reopening with a variable-height selected item

4 participants