2

in my Silverlight 4 application, I have a ScrollViewer. I want to change the width of the vertical Scrollbar of the Scrollviewer, to make it a bit thinner. I have searched for a simple solution, but I do not need/want to restyle the whole Scrollbar. I was thinking about something like:

MyScrollViewer.VerticalScrollbar.Width = 8;

But there is no such Property. Any idea, how to make the scroll bar thinner?

Thanks in advance,
Frank

Aaginor
  • 4,516
  • 11
  • 51
  • 75

2 Answers2

3

There is no direct way of getting the vertical scrollbar of the scrollviewer. Below code will extract the vertical scroll bar from the visualtree and you can do the changes in properties of the 'scrollbar'

ScrollBar vertical = ((FrameworkElement)VisualTreeHelper.GetChild(scrollviewer1, 0)).FindName("VerticalScrollBar") as ScrollBar;
vaibhav
  • 1,028
  • 12
  • 31
  • Thanks vaibhav! Now I have the scrollbar, but changing the width-property can only make the bar wider. Looks like there is some kind of minimum width in the scrollbar-control. And I guess I need to re-template it to get around this :/ – Aaginor May 23 '12 at 07:02
  • hmmm! but why do you need to make the scrollbar thinner? If you dont want to show it, you can set the `VerticalScrollBarVisibility` to `Hidden` – vaibhav May 23 '12 at 07:12
  • For the design of my current project (and I am not in charge for the design, I "just" implement it), I need a thinner scrollbar, because this would better fit in the design over all. – Aaginor Jun 05 '12 at 08:56
  • I can change the template of the ScrollViewer, there is a VerticalScrollBar-Element with the width of 18. When I change it to 17, the element becomes 1 px smaller as expected. But change the width to a value < 17 doesn't change anything. Looks like there is a MinWidth of 17 due to some reason I don't know (and therefor can't change). – Aaginor Jun 05 '12 at 09:46
  • well, buddy, Microsoft has its rules and we are bound to it. Yes you are right, the minimum thickness for the scrollbar is 17. In case you want it less than 17, maybe, you can try with custom scrollviewer – vaibhav Jun 05 '12 at 10:14
0

There is one more Property called MinWidth. If you set that property then the width will get reduced.

Try this :

 ScrollBar vertical = ((FrameworkElement)VisualTreeHelper.GetChild(scrollViewer1, 0)).FindName("VerticalScrollBar") as ScrollBar;
 vertical.MinWidth = 8;
 vertical.Width = 8;