Skip to content

[Skia] ListView: calling ScrollIntoView from SelectionChanged before the first layout pass permanently breaks virtualization (items above the target never render, later containers appear out of order) #24332

Open

Description

@mikernet

Current behavior 🐛

If a ListView gets a fresh ItemsSource and a programmatic SelectedItem in the same beat (in our app both come from x:Bind when the view model populates), and the SelectionChanged handler calls ScrollIntoView on the selected item, the panel ends up in a broken state when the scroll happens before the list has done its first layout over the new source:

  • All items above the selected one are simply missing. The list renders starting at the selected item as if it were the first one.
  • The missing items never get materialized by scrolling. Selecting one of them programmatically afterwards (e.g. a "previous item" button) generates its container, but appends it to the bottom of the list instead of its correct position.

Expected behavior 🎯

The full list renders and is scrolled to the selected item. Worst case, if scrolling this early isn't supported, the scroll should just not happen - the list shouldn't be permanently corrupted with no exception.

How to reproduce it (as minimally and precisely as possible) 🔬

New Uno app, single page:

<Grid>
  <Grid.RowDefinitions>
    <RowDefinition Height="Auto" />
    <RowDefinition Height="*" />
  </Grid.RowDefinitions>
  <Button Grid.Row="0" Content="Select previous" Click="OnSelectPrevious" />
  <ListView Grid.Row="1" x:Name="List" SelectionChanged="OnSelectionChanged" />
</Grid>
private List<string> _items = null!;

public MainPage()
{
    InitializeComponent();
    _items = Enumerable.Range(1, 100).Select(i => $"Item {i}").ToList();
    List.ItemsSource = _items;
    List.SelectedItem = _items[50];
}

private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
    if (List.SelectedItem is { } selected)
        List.ScrollIntoView(selected);
}

private void OnSelectPrevious(object sender, RoutedEventArgs e)
{
    int index = List.SelectedItem is string s ? _items.IndexOf(s) : 1;
    List.SelectedItem = _items[Math.Max(0, index - 1)];
}
  1. Run the desktop head. The list starts at "Item 51" - items 1-50 are gone and can't be scrolled to.
  2. Click "Select previous". "Item 50" appears at the bottom of the list, below "Item 100", selected.

Workaround 🛠️

Deferring the scroll by one dispatcher tick:

private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
    if (List.SelectedItem is not null)
    {
        DispatcherQueue.TryEnqueue(() => {
            if (List.SelectedItem is { } selected)
                List.ScrollIntoView(selected);
        });
    }
}

Renderer 🎨

  • Skia
  • Native

Affected platforms 📱💻🖥️

All platforms 🌍

Uno.Sdk version (and other relevant versions) 📦

6.7.18 and 6.7.0-dev.165

IDE version 🧑‍💻

No response

Anything else we need to know? 💬

Looks like the virtualization window gets seeded at the target index when the scroll request arrives before the panel has laid out the new source, and the leading range is never backfilled after that - which would explain both symptoms (missing leading items, and out-of-order container placement when one of them is materialized later).

Activity

  1. added theissue type on Sep 1, 2026
  2. added
    triage/untriaged
    on Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage/untriaged

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions