1、通过listview.ScrollIntoView()方法实现:
滚动到顶端:listview.ScrollIntoView(listview.Items[0]);
滚动到低端:
int count = listview.Items.Count;
int index = count - 1; listview.ScrollIntoView(listview.Items[index]);
滚动到指定位置:listview.ScrollIntoView(listview.Items[index]);
2、通过控制listview内部的ScrollView控件实现:
Border bor = VisualTreeHelper.GetChild(listview, 0) as Border; //listview内部第一层为Border容器
ScrollViewer sview = bor.Child as ScrollViewer; //border内部的child即为scrollview,正是我们接下来操作需要的控件
OK!接下来可以实现之前的功能:
滚动到顶端:sview.ScrollToTop();
滚动到低端:sview.ScrollToBottom();
滚动到指定位置:sview.ScrollToVerticalOffset(positin); //position为垂直方向滚动的高度,同之前的index不同
ScrollView其他相关的方法:
1 // 2 // 摘要: 3 // Scrolls the System.Windows.Controls.ScrollViewer content downward by one page. 4 public void PageDown(); 5 // 6 // 摘要: 7 // Scrolls the System.Windows.Controls.ScrollViewer content to the left by one page. 8 public void PageLeft(); 9 // 10 // 摘要: 11 // Scrolls the System.Windows.Controls.ScrollViewer content to the right by one 12 // page. 13 public void PageRight(); 14 // 15 // 摘要: 16 // Scrolls the System.Windows.Controls.ScrollViewer content upward by one page. 17 public void PageUp(); 18 // 19 // 摘要: 20 // Scrolls vertically to the end of the System.Windows.Controls.ScrollViewer content. 21 public void ScrollToBottom(); 22 // 23 // 摘要: 24 // Scrolls vertically to the end of the System.Windows.Controls.ScrollViewer content. 25 public void ScrollToEnd(); 26 // 27 // 摘要: 28 // Scrolls vertically to the beginning of the System.Windows.Controls.ScrollViewer 29 // content. 30 public void ScrollToHome(); 31 // 32 // 摘要: 33 // Scrolls the content within the System.Windows.Controls.ScrollViewer to the specified 34 // horizontal offset position. 35 // 36 // 参数: 37 // offset: 38 // The position that the content scrolls to. 39 public void ScrollToHorizontalOffset(double offset); 40 // 41 // 摘要: 42 // Scrolls horizontally to the beginning of the System.Windows.Controls.ScrollViewer 43 // content. 44 public void ScrollToLeftEnd(); 45 // 46 // 摘要: 47 // Scrolls horizontally to the end of the System.Windows.Controls.ScrollViewer content. 48 public void ScrollToRightEnd(); 49 // 50 // 摘要: 51 // Scrolls vertically to the beginning of the System.Windows.Controls.ScrollViewer 52 // content. 53 public void ScrollToTop(); 54 // 55 // 摘要: 56 // Scrolls the content within the System.Windows.Controls.ScrollViewer to the specified 57 // vertical offset position. 58 // 59 // 参数: 60 // offset: 61 // The position that the content scrolls to. 62 public void ScrollToVerticalOffset(double offset);