views:

29

answers:

1

I've got a FlowDocumentScrollViewer with a vertical scrollbar. Now I want to know its position and also be able to change it.

A: 

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.

Hedge