I have a ScrollViewer and in that I am showing the Vertical Scrollbar, Now on changing resolution of the system I want to get the width of the scrollbar. I went through One StackOverflow Post there they mention to check for SystemParameters.ScrollWidth Property but again I din find any help from their. Can anybody please help me to fix my issue. Any answer will be appreciated.
Asked
Active
Viewed 2.0k times
28
-
2Check for this code, This will give you the default Scrollbar width: double scrollBarwidth=SystemParameters.VerticalScrollBarWidth; By the way why you are looking for it, any how the default vale of the VerticalScrollBarWidth is 17 I think. – SharpUrBrain Apr 18 '11 at 14:20
-
@SharpUrBrain: Yeah I checked, it is giving me 17 pixel but I was thinking whether its changing according to DPI settings so that's why I was looking for it. – Apr 19 '11 at 04:03
2 Answers
49
I think SystemParameters.VerticalScrollBarWidth
is what you are looking for.

Fredrik Mörk
- 155,851
- 29
- 291
- 343
-
17
-
5I got a cast exception because the value is a double, but ColumnDefinition is a GridLength. The solution I used:
– Melvyn Oct 12 '16 at 08:20
12
I am not sure if this is the correct answer. Every WPF control can be restyled so even the scrollbar. So SystemParameters.VerticalScrollBarWidth works only if it is used as default scrollbar. The correct solution would be to find the vertical scrollbar in the visual tree and measure it's ActualWidth. It is the most precise measurement.

Patrik
- 1,286
- 1
- 31
- 64
-
-
@Grubsnik maybe by binding to a property that you'll create ... nothing straight forwards pops to mind – Noctis Nov 03 '15 at 03:59
-
@Grubsnik If youcan provide the XAML I can try to write it. It is a custom solution so it is hard to give you and immediate answer. – Patrik Nov 03 '15 at 11:10
-
@Patrik thanks for the offer, but the XAML code and project is long gone from my mind at this point. Can't even remember the exact problem I was trying to solve. – Grubsnik Nov 12 '15 at 10:53
-
Exactly this.... I wanted to offset another uielement by the scrollbar width if the visibility changed. To do this I created a couple converters, one that converts a double to thickness with a mask (top,right etc) and a second that derives from this, taking a scrollviewer and passing in the scrollbar width. – Billy Jake O'Connor Mar 03 '19 at 16:55