UWP using ChangeView() on a ScrollViewer so that the focused item can be placed with a specific offset [C#]
The initial need was that I needed to be able to sync two listview together, however one of these listview had horizontal items and was not selectable which meant that it would not inform the first listview that the selected view had changed.
The first listview is not only and indicator but can also allow to quickly access a certain row in our main listview, here is quick screenshot to better understand what I wanted to do, in red the two selected items that need to be sync and in the other colors that other ListView.
The main issue was to be able to detect when the user scrolled down on the second ListView Vertical and to also know at what index position he was at in the listview.
First we need to get the ScrollView of our ListView to detect when the user was scrolling.
We will create class ListViewBaseExtension.cs which will hold the following method
Now let's look at our method called ScrollViewerListView_ViewChanging that handles the ViewChanging event from our scrollViewer.
Everytime we will need to get the position of our items in the list using GetAllItemsPositions(), also we need to calculate the height that that user has scrolled down which will give us a currentVerticalPosition. We will then use this to find an item that is on this position, which will then allow us to inform which item should be selected on the first listview: