AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
26.15k stars 2.27k forks source link

ScrollBar of ListBox is flickered when scrolling with various item sizes #11989

Open hamster620 opened 1 year ago

hamster620 commented 1 year ago

Describe the bug ScrollBar of ListBox is flickered when scrolling if items of ListBox have various sizes (height).

To Reproduce

  1. Add a ListBox.
  2. Set DataTemplate/ItemTemplate to generate items with various sizes
  3. Scroll the ListBox.

Expected behavior ScrollBar should be smooth/stable when scrolling.

Screenshots

https://github.com/AvaloniaUI/Avalonia/assets/26860570/40abab8a-237b-42d6-9110-fd5edfeeddba

Desktop (please complete the following information):

hez2010 commented 1 year ago

I think it is somwhat expected because we can only estimate the position of scrollbar. Otherwise we have to give up on virtualization and instead materialize all items in the list, which will lead to unacceptable performance.

hamster620 commented 1 year ago

I noticed that starting from 11.0.0-rc1.1 the scrolling of ListBox is no longer aligned to top of first visible item which may causes the symptom I described. In our use case the item size varies according to number of lines of text of each item, so current scrolling behavior is unacceptable in this case.

In our app it is fine to elimate smooth scrolling of ListBox in order to keep thumb of scrollbar stable when scrolling. But I cannot find way to change behavior of VirtualizationStackPanel to disable smooth scrolling.

robloo commented 1 year ago

In our app it is fine to elimate smooth scrolling of ListBox in order to keep thumb of scrollbar stable when scrolling. But I cannot find way to change behavior of VirtualizationStackPanel to disable smooth scrolling.

You might have to switch the ItemsPanel from VirtualizationStackPanel to just StackPanel and disable virtualization entirely. This is only possible if you don't have so many items.