WPF: Determine/Set position of vertical Scrollbar
I've got a FlowDocumentScrollViewer with a vertical scrollbar. Now I want to know its posit开发者_开发技巧ion and also be able to change it.
Looking up the visual tree seems to be the best way to get the ScrollViewer-Object.
DependencyObject obj = this.DocumentScrollViewer;
do
{
if (VisualTreeHelper.GetChildrenCount(obj) > 0)
{
obj = VisualTreeHelper.GetChild(obj as Visual, 0);
}
}
while (!(obj is ScrollViewer));
this.scroller = obj as ScrollViewer;
That comes with methods such as ScrollToVerticalOffset(..) and ScrollableHeight which enable me to do everything I wanted.
精彩评论