Alex Rivera | Logout

Setting the scrollbar position of a ListBox

Asked 2008-10-01T20:18:58.463
10

Can I programatically set the position of a WPF ListBox's scrollbar? By default, I want it to go in the center.

Edit
Report

1 Answer

0

I've just changed a bit code of Zamboni and added position calculation.

var border = VisualTreeHelper.GetChild(list, 0) as Decorator;
if (border == null) return;
var scrollViewer = border.Child as ScrollViewer;
if (scrollViewer == null) return;
scrollViewer.ScrollToVerticalOffset((scrollViewer.ScrollableHeight/list.Items.Count)*
                                    (list.Items.IndexOf(list.SelectedItem) + 1));
answered 2012-06-25T20:12:29.127

Your Answer