Description
Current behavior 🐛
Every selection change in a ListView or GridView (including the inner list of a TreeView) scrolls the newly selected item into view, whether or not the list has focus. Setting SelectedItem or SelectedIndex from code on a list that doesn't have focus scrolls the list to that item, even far off-screen.
In Multiple selection mode it goes the other way: the first selection isn't brought into view even when the list has focus.
Expected behavior 🎯
Match WinUI (Selector::SetFocusedItem, measured on Windows App SDK 1.7):
- A list scrolls a new selection into view only while it has focus, by the minimum distance. Clicking a row focuses it, so a row cut off at the edge still scrolls just enough to be fully visible.
- A list without focus, or one that lost focus, never scrolls when its selection is changed from code.
- In
Multiplemode, only the first selection (from nothing selected) is brought into view.
How to reproduce it (as minimally and precisely as possible) 🔬
<ListView x:Name="list" Height="200" />with 100 items, plus aButtonthat runslist.SelectedIndex = 50;.- Without clicking into the list first, click the button.
- Uno: the list scrolls to item 50. WinUI: the list stays at the top.
Workaround 🛠️
Save ScrollViewer.VerticalOffset before changing the selection and restore it with ChangeView afterwards.
Affected platforms 📱💻🖥️
All platforms 🌍
Uno.Sdk version (and other relevant versions) 📦
Current master.
IDE version 🧑💻
N/A
Anything else we need to know? 💬
Uno already has WinUI's code path ported, with the scroll commented out (Selector.SetFocusedItem); the unconditional scroll comes from Selector.ScrollSelectionIntoView.
Activity