Scrolling Scrollviewer on Mouse Drag at the boundaries

If you have used the scrollviewer control then one thing that you might have noticed is that the viewer doesnt scroll if we drag some data towards the boundary of the control. It would be nice if we could get the viewer to scroll on mouse drag. Try the following Xaml code - type in several lines of text so that the viewer scrolls. Now drag some text to the boundary - oops!! no scrolling ..

<ScrollViewer xmlns='' 
xmlns:x='' Height="200">
      <TextBox AcceptsReturn='True' VerticalScrollBarVisibility='Visible'>text</TextBox>
</ScrollViewer >

Dont sweat it :), Dan Crevier came up with some code which addresses the above. The code extends the scrollviewer to handle the up/down scrolling on dragging to the upper/lower boundaries of the scrollviewer.  The code is attached to this post and will also be posted on the WPF community site. 🙂


Skip to main content