0
votes

I have an UserControl containing a ScrollViewer with "sychronized" ScrollBar associated with it binding both the ViewportSize and Maximum ScrollBar's properties, simplified code:

//xaml
<ScrollViewer x:Name="scViewer" <!--and its content-->/>
<ScrollBar ViewportSize="{Binding ViewportWidth, ElementName=scViewer}" 
           Maximum="{Binding ScrollableWidth, ElementName=scViewer}" x:Name="scHBar"
           Orientation="Horizontal" Scroll="HScrollBar_Scroll"/>
//code behind
private void HScrollBar_Scroll(object sender, ScrollEventArgs e)
{
    scViewer.ScrollToHorizontalOffset(e.NewValue);//and the other way around
}

It works as expected, except when user clicks up/down arrows on ScrollBar the speed is very slow, 0.1px for each click to be precise, which requires user to click 10 times(!) to scroll a pixel. Strangely enough, the mouse wheel scrolling speed is fine just as dragging the bar speed is.
The only solution which comes to my mind is multiplying the e.NewValue delta, however I dont know whether the source was one of the arrow buttons(not mouse wheel or bar drag) so it would break every other type of interaction.
There are quite a lot questions about scrolling speed of mouse wheel, however I was unable to find a single one mentioning the speed when clicking ScrollBar's arrow buttons. How do I change the ScrollBar's arrow buttons click scroll speed?

1
thanks but please note it is not what I am not asking about - I already have the Mouse wheel working, the trouble are the arrow buttons on top/bottom of the ScrollBar. - wondra

1 Answers

2
votes

The Scrollbar also has properties SmallChange and LargeChange, defaulting to 0.1 and 1 respectively. The first one is controlling the speed of scrolling when clicking the arrow buttons, so changing the value:

<ScrollBar SmallChange="30" LargeChange="150"
       ViewportSize="{Binding ViewportWidth, ElementName=scViewer}" 
       Maximum="{Binding ScrollableWidth, ElementName=scViewer}" x:Name="scHBar"
       Orientation="Horizontal" Scroll="HScrollBar_Scroll"/>

worked for me.