Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrolling a ListBox with differing item height with virtualization enabled messes up the arrange of the selected item #17935

Open
tvass83 opened this issue Jan 9, 2025 · 2 comments
Labels
bug help-wanted A contribution from the community would be most welcome.

Comments

@tvass83
Copy link

tvass83 commented Jan 9, 2025

Describe the bug

This is a regression b/w 0.10.22 .. 11.2.3.

InvalidBoundsForSelectedItem

Seems that the selected item is cached (in _focusedElement) and is not recycled as regular items that leave the viewport.

// Ensure that the focused element is in the correct position.
if (_focusedElement is not null && _focusedIndex >= 0)
{
u = GetOrEstimateElementU(_focusedIndex);
var rect = orientation == Orientation.Horizontal ?
new Rect(u, 0, _focusedElement.DesiredSize.Width, finalSize.Height) :
new Rect(0, u, finalSize.Width, _focusedElement.DesiredSize.Height);
_focusedElement.Arrange(rect);
}

Then in VirtualizingStackPanel.Arrange(), the cached item is also arranged but with incorrectly calculated finalSize.

var estimatedSize = EstimateElementSizeU();
// TODO: Use _startU to work this out.
return index * estimatedSize;

The calculation currently just averages the desired height of the realized containers, that only works fine when using identical item height values.

To Reproduce

Check the following repro apps to see the different behavior in Avalonia 0.10.22 vs 11.2.3.
There's also a WPF app here that works as expected.
https://github.com/tvass83/AvaloniaIssues/tree/main/InvalidBoundsForSelectedItem

Expected behavior

The selected item shall not randomly appear on screen while scrolling through the items.

Avalonia version

11.2.3

OS

No response

Additional context

Considered the following issues & PRs before filing this issue:
#9269
#2144
#10367
#17349
#10892

@tvass83 tvass83 added the bug label Jan 9, 2025
@timunie
Copy link
Contributor

timunie commented Jan 9, 2025

Hey @tvass83 ,

Since you have already started to investigate the root cause, feel free to provide a PR in case you have an idea how to fix the measurement.

@timunie timunie added the help-wanted A contribution from the community would be most welcome. label Jan 9, 2025
@tvass83
Copy link
Author

tvass83 commented Jan 10, 2025

Seems like @grokys is the expert in this area. Steven, do you think there could be a simple fix for this issue?
I understand that the term simple & virtualization are not best friends though... 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help-wanted A contribution from the community would be most welcome.
Projects
None yet
Development

No branches or pull requests

2 participants