AutoScroller
- New release: Improved drag mode and drag-and-drop example added.
AutoScroller is a C# class for Silverlight 2 (it also works with SL3) . It adds automatic scrolling to a ScrollViewer. This is useful, for example, in a drag-and-drop interface inside a ScrollViewer: If an object is dragged to the edge, automatic scrolling can be triggered
Rationale: This feature seems like a useful extension to ScrollViewer. ScrollViewer is a sealed class. Applying the extension via a separate class seems like a neat approach to adding the feature.
Usage
Mode Property
- Mode.Drag: If the mouse is dragged near the edge of the ScrollViewer, the ScrollViewer will scroll in the direction of that edge. It will stop scrolling when the mouse is moved away, or the mouse button is released. This is useful for drag and drop interfaces inside a ScrollViewer.
- Mode.Auto: If the mouse is near the edge of the ScrollViewer, the ScrollViewer will scroll in the direction of that edge. It will stop scrolling when the mouse is moved away.
- Mode.Off: No auto scrolling is applied.
ScrollLeft, ScrollUp, SrollRight, ScrollDown Properties
- (Boolean) Scroll in the appropriate direction.
ScrollArea Property
- Defines the width (in pixels) of the zone at the edge of the ScrollViewer that will trigger automatic scrolling. Default is 40.
ScrollPixelsPerTick Property
- The number of pixels scrolled per 100 milliseconds.
TargetCanvas Property
- This is the canvas which drag-and-drop objects are located on. If it is not specified it defaults to the ScrollViewer content (if a Canvas).
ClearControl() Method
- Clears references in the control to make it available for garbage collection.
The targetted ScrollViewer is set via a constructor parameter, and cannot be changed, except via the ClearControl() method.
Notes
- If the background of the content element is null, then the handlers will not respond while they are over empty spaces within the content (unless a content element has captured the mouse). Setting the background of the content element to Transparent will fix this, if it is an issue.
- If mouse events have the handled property set to true by controls, it will prevent event bubble up, and may interfere with automatic scroll function.
- AutoScrolling will work on a ScrollViewer with a Scrollbar's visibility set to Hidden. It won't work on that axis if the Scrollbar's visibility is set to Disabled.