Lester's WPF\SL Blog

Simple, Easy & Beautiful

Scrolling Scrollviewer on Mouse Drag at the boundaries

Scrolling Scrollviewer on Mouse Drag at the boundaries

  • Comments 1

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='http://schemas.microsoft.com/winfx/2006/xaml/presentation' 
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' 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. :)

Attachment: DragDropScrollViewer.cs