AvaloniaUI / Avalonia.Controls.ItemsRepeater

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

ItemsRepeater's child not found in its Children collection exception #9

Open milkywayfarer opened 3 years ago

milkywayfarer commented 3 years ago

Describe the bug ItemsRepeater using UniformGridLayout with 9 or more children gives the exception when you scroll it back and forth. It seems like ItemsRepeater does not load all the binded items together and unloads items that are unreachable by the user which might cause this kind of problems. It unloads the first item in my collection when I scroll to the bottom (you can see it in Avalonia DevTools) and does not load it back, leaving just blank space and crashing after I attempt to scroll again.

To Reproduce Steps to reproduce the behavior:

  1. Create a random UserControl with the size of 244x226 and margins 0 20 19 0 (a Panel with random background should work)
  2. Create a ViewModel that has an AvaloniaList<UserControl> to bind ItemsRepeater to
  3. In this ViewModel constructor, add 10 or more UserControl to the AvaloniaList
  4. Create a ScrollViewer with the size of 572x510, put ItemsRepeater with UniformGridLayout inside of it and bind it to the AvaloniaList
  5. Run and scroll to the bottom and back - the first element should disappear, and scrolling back to the bottom crashes the app with System.InvalidOperationException: 'ItemsRepeater's child not found in its Children collection.'

Expected behavior Scrolling should not make the 0th item in the collection disappear and crash the app.

Desktop (please complete the following information):

Additional context I saw the same problems with XML in https://github.com/microsoft/microsoft-ui-xaml/pull/2969 and https://github.com/microsoft/microsoft-ui-xaml/issues/2834. Maybe that could help.