开发者

Scrollbar Size in ScrollViewer

开发者 https://www.devze.com 2022-12-31 13:08 出处:网络
How can I programatically determine the width or height of a Scrollbar in the ScrollViewer?Not the current size based on t开发者_如何学Pythonhe current state of the ScrollViewer (since I can simply te

How can I programatically determine the width or height of a Scrollbar in the ScrollViewer? Not the current size based on t开发者_如何学Pythonhe current state of the ScrollViewer (since I can simply test the visibility of the scrollbar and calculate against the ViewerPortWidth/Height and the ScrollViewer ActualWidth/Height).

I need to know what size the Scrollbar's could be based on the templated width. The default is 18 (with a margin of -1). But we all know what could happen if I use the magic number of 18 in my calculations. Some of my users could template the Scrollbars in the ScrollViewer then I'd be screwed.

Thanks!


You can use SystemParameters.ScrollWidth.


You can use Silverlight Toolkit's VisualTreeHelper in the following way:

var verticalScrollbar = view.GetVisualChildren().OfType<FrameworkElement>()
        .FirstOrDefault(e => e.Name == "VerticalScrollBar");
var horizontalScrollbar = view.GetVisualChildren().OfType<FrameworkElement>()
        .FirstOrDefault(e => e.Name == "HorizontalScrollBar");
var width = verticalScrollbar == null ? 0 : verticalScrollbar.ActualWidth;
var height = horizontalScrollbar == null ? 0 : horizontalScrollbar.ActualHeight;

where view is an instance of ScrollViewer (I guess you've got the instance).

0

精彩评论

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