WPF: How to scroll a ListView control horizontally?

I need to manually scroll the contents of the ListView control on the left.

It gets called automatically when I call scrollIntoView, but only if the item to scroll does not display. The ListView will scroll to the item and move horizontally to the left. Just as I need it.

But if the scroll item is already visible, nothing will happen, and for this very reason I need to scroll left manually.

+4
source share
1 answer

You can find the ScrollViewer for the ListView by going through the visual tree, and then call ScrollToLeftEnd . Something like this should work

 private void ScrollListViewToLeft(ListView listView) { ScrollViewer listViewScrollViewer = GetVisualChild<ScrollViewer>(listView); listViewScrollViewer.ScrollToLeftEnd(); } private static T GetVisualChild<T>(DependencyObject parent) where T : Visual { T child = default(T); int numVisuals = VisualTreeHelper.GetChildrenCount(parent); for (int i = 0; i < numVisuals; i++) { Visual v = (Visual)VisualTreeHelper.GetChild(parent, i); child = v as T; if (child == null) { child = GetVisualChild<T>(v); } if (child != null) { break; } } return child; } 
+3
source

Source: https://habr.com/ru/post/1338890/


All Articles