Skip to content

Add ListView ScrollIntoView and ListViewPersistenceHelper samples - #2179

Merged
Niels Laute (niels9001) merged 9 commits into
microsoft:mainfrom
niels9001:add-listview-scroll-samples
Aug 14, 2026
Merged

Niels Laute (niels9001) merged 9 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.

Niels Laute (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>

@marcelwgn Marcel W. (marcelwgn) left a comment

Copy link
Copy Markdown
Contributor

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!

@niels9001
Niels Laute (niels9001) enabled auto-merge (squash) July 6, 2026 18:35
@niels9001

Copy link
Copy Markdown
Collaborator Author

/azp run

@niels9001

Copy link
Copy Markdown
Collaborator Author

/azp run

Remove the stale SavedPositionTextBlock reference left after the position text was removed, and use explicit types in the new sample code.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 4dc1511d-17f9-43b2-84e7-1e55bff5b873
@marcelwgn

Copy link
Copy Markdown
Contributor

/azp run

@niels9001
Niels Laute (niels9001) merged commit 8854551 into microsoft:main Aug 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants