开发者

WPF: Determine/Set position of vertical Scrollbar

开发者 https://www.devze.com 2023-01-17 03:42 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消