Skip to content

Add ListView ScrollIntoView and ListViewPersistenceHelper samples#2179

Open
niels9001 wants to merge 4 commits into
microsoft:mainfrom
niels9001:add-listview-scroll-samples
Open

Add ListView ScrollIntoView and ListViewPersistenceHelper samples#2179
niels9001 wants to merge 4 commits into
microsoft:mainfrom
niels9001:add-listview-scroll-samples

Conversation

@niels9001
Copy link
Copy Markdown
Collaborator

Adds two new ControlExample sections to the ListView samples page, adapted from the UWP XamlListView reference sample.

1. Save / restore scroll position

Demonstrates ListViewPersistenceHelper.GetRelativeScrollPosition and SetRelativeScrollPositionAsync - the same API used to restore a ListView's scroll position after navigating away and back. Surfaced inline as Save position / Restore position buttons (and the captured opaque position string) so the behavior is observable inside a single ControlExample.

2. ScrollIntoView

NumberBox for the target index and a ComboBox for ScrollIntoViewAlignment (Default vs Leading) drive ListView.ScrollIntoView.

Changes

  • WinUIGallery/Samples/ListView/ListViewPage.xaml - two new ControlExample blocks.
  • WinUIGallery/Samples/ListView/ListViewPage.xaml.cs - new collections, OnNavigatedTo seeding, and handlers for the two samples.
  • WinUIGallery/Samples/ListView/ListviewRestoreScrollPosition.txt - displayed snippet.
  • WinUIGallery/Samples/ListView/ListviewScrollIntoView.txt - displayed snippet.

Builds clean on x64 Debug.

niels9001 and others added 4 commits May 22, 2026 17:18
Two new ControlExamples on the ListView samples page, based on the UWP XamlListView reference sample:

- ScrollIntoView: NumberBox + alignment ComboBox drive ListView.ScrollIntoView with ScrollIntoViewAlignment.Default or Leading.
- Save/restore scroll position: demonstrates ListViewPersistenceHelper.GetRelativeScrollPosition and SetRelativeScrollPositionAsync, the same API a real app would use to restore position after navigating away and back.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Items are prefixed with their 1-based index (e.g. '1. John Doe') so it is easy to verify save/restore and ScrollIntoView landed on the expected entry.
- NumberBox now sets Maximum, SmallChange/LargeChange, and ValidationMode so manually typed indices are preserved instead of reverting.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@niels9001 niels9001 requested a review from marcelwgn May 28, 2026 14:42
Copy link
Copy Markdown
Contributor

@marcelwgn marcelwgn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides the showing of the raw position blob, LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants