AvaloniaUI / Avalonia.Controls.ItemsRepeater

ItemsRepeater is a light-weight control to generate and present a collection of items.
MIT License
2 stars 1 forks source link

`ItemsRepeater` inside `ScrollViewer`, DataContext inconsistencies #21

Open hahagu opened 1 year ago

hahagu commented 1 year ago

Describe the bug Using the ItemsRepeater inside ScrollViewer causes inconsistencies with DataContext. When I scroll to the end of the ScrollViewer, or close to, the first few items' DataContext becomes null, and when going back up, it may get mixed around with other objects.

To Reproduce

Steps to reproduce the behavior:

  1. Have a ItemsRepeater control inside ScrollViewer and populate
  2. Populate the ItemsRepeater
  3. Scroll down the ScrollViewer far enough
  4. Monitor the DataContext of ItemsRepeater

Expected behavior

DataContext is supposed to not become null, or get jumbled around.

Screenshots

https://github.com/AvaloniaUI/Avalonia/assets/3746349/1fd285e2-c529-4ede-b68f-cc01b1cd32a1

Desktop (please complete the following information):

Additional context

Bug case minimal reproducible example bug_case.zip

timunie commented 1 year ago

version means Avalonia version, not OS version. Can you please add this? thx.

hahagu commented 1 year ago

version means Avalonia version, not OS version. Can you please add this? thx.

Hey, thanks for getting back.

I've fixed the version number.

Sorry for the confusion!

emmauss commented 9 months ago

ItemsRepeater uses virtualization. As you scroll items out of view, their containers will be used for items that are about to be shown, thus their Datacontext is set to the new items. The datacontext of each real item in the Source is still preserved, but its position in the Logical tree is not representative of it's visual location.