There is no way of doing that using the ListView
element. Instead, you need to access its ScrollViewer
and then you can use the ScrollViewer.ScrollToVerticalOffset
Method to set the vertical position of the ScrollViewer
. You'll also need to use the ScrollViewer.VerticalOffset
, ScrollViewer.VerticalOffset
, ScrollViewer.ViewportHeight
and ScrollViewer.ExtentHeight
properties to gauge where you are in the ScrollViewer
.
From the ScrollViewer
Class page on MSDN:
The area that includes all of the content of the ScrollViewer is the extent. The visible area of the content is the viewport.
Finally, how do you get the ScrollViewer
from the ListView
? I can't guarantee that this will work on a ListView
, but it does on a ListBox
. you can use the VisualTreeHelper.GetChild
Method to delve into the visual tree of the ListView
and it should contain a Border
and then the ScrollViewer
, so you should be able to do something like this:
Border border = (Border)VisualTreeHelper.GetChild(YourListView, 0);
ScrollViewer scrollViewer = VisualTreeHelper.GetChild(border, 0) as ScrollViewer;
if (scrollViewer != null)
{
scrollViewer.ScrollToVerticalOffset(60.0);
}
If you do get an error with what the GetChild
method returns, it'll be easy to adjust by debugging it. Just put a breakpoint there and see what each child type is and add another line with one of those elements... eventually, it should find the ScrollViewer
. However, I think that that code should be fine.