Basically, the ScrollViewer is built-in to ListView. Suppose you developed a desktop application based on UWP. In this application, there's one page containing StudentListView. One day you want to scroll it to its top. A first question will be asked that: how to get ScrollViewer from ListView? The following code will answer this question:
XAML
<ListView x:Name="StudentListView"></ListView>
Code Behind
Border border = VisualTreeHelper.GetChild(StudentListView, 0)
as Border;
ScrollViewer scrollViewer = VisualTreeHelper.GetChild(border, 0)
as ScrollViewer;
Next, you can use the following code to scroll StudentListView to its top:
if (scrollViewer != null) {
scrollViewer.ChangeView(0, 0, 1);
}
Hope this post would be useful for you.
Happy coding :)
Top comments (0)