ExtendedScrollViewer
A scroll viewer with slim, rounded, fully colourable scroll bars that can sit beside the content or float over it, in the manner of a touch or mobile interface.
public class ExtendedScrollViewer : ScrollViewer
Inherits from / implements: ScrollViewer
Remarks
Use it in place of a ScrollViewer wherever the standard Windows scroll bars look
heavy against the rest of the design: a dashboard, a chat or activity feed, a side panel, a
touch-screen list. Everything a ScrollViewer does – scrolling with the wheel, the
keyboard and touch, ScrollViewer.ScrollToTop and the other methods,
ScrollViewer.VerticalScrollBarVisibility, ScrollViewer.CanContentScroll
- works unchanged.
Size and layout
VerticalScrollBarWidth and HorizontalScrollBarHeight set the
thickness of the bars, and ThumbCornerRadius rounds the thumb. With
ShouldOverlayContent on, the bars float over the content instead of taking room
beside it, so the content uses the full width and height of the viewer.
Line buttons
By default the bars have no arrow buttons at their ends – only a track and a thumb. Turn them
on with IsVerticalLineScrollerVisualsAvailable and
IsHorizontalLineScrollerVisualsAvailable; they are square, as wide as the bar, and
have colours of their own for the normal, hover and pressed states.
Colours
The track, the thumb (at rest, under the pointer and while dragged) and the line buttons each
have a brush. The defaults given on each property are the ones used when no Binarymission skin is
in force; with a skin (BinarySkinManager) the colours come from the skin, and any
brush you set on the control wins over both.
Defaults
The default style gives 18-pixel bars that appear only when the content overflows
(Auto both ways), a fully rounded thumb, no line buttons, a
FrameworkElement.Margin of 8 logical pixels and content aligned to the top left.
Examples
An activity feed with thin overlay scroll bars and a dark thumb.
<Window x:Class="Crm.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sv="clr-namespace:Binarymission.WPF.Controls.Scrollers;assembly=Binarymission.WPF.Controls.ExtendedScrollViewer"
Title="Account activity" Width="420" Height="520">
<sv:ExtendedScrollViewer ShouldOverlayContent="True"
VerticalScrollBarWidth="8"
HorizontalScrollBarVisibility="Disabled"
ThumbCornerRadius="4"
TrackBackgroundBrush="Transparent"
ThumbOnNormalFillBrush="#88505A66"
ThumbOnMouseOverBackgroundBrush="#CC505A66"
ThumbOnPressedBackgroundBrush="#FF2F3740">
<ItemsControl ItemsSource="{Binding Activities}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Margin="12,8">
<TextBlock FontWeight="SemiBold" Text="{Binding Title}" />
<TextBlock Foreground="Gray" Text="{Binding When, StringFormat=g}" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</sv:ExtendedScrollViewer>
</Window>A viewer for a large diagram, with arrow buttons on both bars, built in code.
using System;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Binarymission.WPF.Controls.Scrollers;
ExtendedScrollViewer viewer = new ExtendedScrollViewer
{
VerticalScrollBarWidth = 14,
HorizontalScrollBarHeight = 14,
IsVerticalLineScrollerVisualsAvailable = true,
IsHorizontalLineScrollerVisualsAvailable = true,
HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
LineScrollerOnNormalBackgroundBrush = Brushes.SteelBlue,
LineScrollerOnMouseOverBackgroundBrush = Brushes.DodgerBlue,
Content = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Images/site-plan.png")) }
};See also
Members at a glance
| Properties | |
|---|---|
HorizontalScrollBarHeight | Gets or sets the thickness of the horizontal scroll bar. |
HorizontalScrollBarMinHeight | Gets or sets a height the horizontal scroll bar is never made thinner than. |
IsHorizontalLineScrollerVisualsAvailable | Gets or sets whether the horizontal scroll bar has arrow buttons at its ends that scroll a little way left or right at each click. |
IsVerticalLineScrollerVisualsAvailable | Gets or sets whether the vertical scroll bar has arrow buttons at its ends that scroll a little way up or down at each click. |
LineScrollerArrowFillBrush | Gets or sets the colour of the small triangle drawn on each arrow button. |
LineScrollerOnMouseOverBackgroundBrush | Gets or sets the fill of an arrow button while the pointer is over it. |
LineScrollerOnMouseOverBorderBrush | Gets or sets the colour of the outline round an arrow button while the pointer is over it. |
LineScrollerOnNormalBackgroundBrush | Gets or sets the fill of each arrow button while the pointer is not over it. |
LineScrollerOnNormalBorderBrush | Gets or sets the colour of the one-pixel outline round each arrow button while the pointer is not over it. |
LineScrollerOnPressedBackgroundBrush | Gets or sets the fill of an arrow button while it is held down. |
LineScrollerOnPressedBorderBrush | Gets or sets the colour of the outline round an arrow button while it is held down. |
ShouldOverlayContent | Gets or sets whether the scroll bars float over the content rather than taking room of their own beside it. |
ThumbCornerRadius | Gets or sets how far the corners of the scroll bars' thumbs are rounded. |
ThumbOnMouseOverBackgroundBrush | Gets or sets the colour of a scroll bar's thumb while the pointer is over it. |
ThumbOnNormalFillBrush | Gets or sets the colour of the scroll bars' thumbs while the pointer is not over them. |
ThumbOnPressedBackgroundBrush | Gets or sets the colour of a scroll bar's thumb while it is being dragged. |
TrackBackgroundBrush | Gets or sets the colour of the scroll bars' tracks – the channel the thumb slides along. |
VerticalScrollBarMinWidth | Gets or sets a width the vertical scroll bar is never made thinner than. |
VerticalScrollBarWidth | Gets or sets the thickness of the vertical scroll bar. |
| Fields | |
HorizontalScrollBarHeightProperty | Identifies the HorizontalScrollBarHeight dependency property. |
HorizontalScrollBarMinHeightProperty | Identifies the HorizontalScrollBarMinHeight dependency property. |
IsHorizontalLineScrollerVisualsAvailableProperty | Identifies the IsHorizontalLineScrollerVisualsAvailable dependency property. |
IsVerticalLineScrollerVisualsAvailableProperty | Identifies the IsVerticalLineScrollerVisualsAvailable dependency property. |
LineScrollerArrowFillBrushProperty | Identifies the LineScrollerArrowFillBrush dependency property. |
LineScrollerOnMouseOverBackgroundBrushProperty | Identifies the LineScrollerOnMouseOverBackgroundBrush dependency property. |
LineScrollerOnMouseOverBorderBrushProperty | Identifies the LineScrollerOnMouseOverBorderBrush dependency property. |
LineScrollerOnNormalBackgroundBrushProperty | Identifies the LineScrollerOnNormalBackgroundBrush dependency property. |
LineScrollerOnNormalBorderBrushProperty | Identifies the LineScrollerOnNormalBorderBrush dependency property. |
LineScrollerOnPressedBackgroundBrushProperty | Identifies the LineScrollerOnPressedBackgroundBrush dependency property. |
LineScrollerOnPressedBorderBrushProperty | Identifies the LineScrollerOnPressedBorderBrush dependency property. |
ShouldOverlayContentProperty | Identifies the ShouldOverlayContent dependency property. |
ThumbCornerRadiusProperty | Identifies the ThumbCornerRadius dependency property. |
ThumbOnMouseOverBackgroundBrushProperty | Identifies the ThumbOnMouseOverBackgroundBrush dependency property. |
ThumbOnNormalFillBrushProperty | Identifies the ThumbOnNormalFillBrush dependency property. |
ThumbOnPressedBackgroundBrushProperty | Identifies the ThumbOnPressedBackgroundBrush dependency property. |
TrackBackgroundBrushProperty | Identifies the TrackBackgroundBrush dependency property. |
VerticalScrollBarMinWidthProperty | Identifies the VerticalScrollBarMinWidth dependency property. |
VerticalScrollBarWidthProperty | Identifies the VerticalScrollBarWidth dependency property. |
Properties
HorizontalScrollBarHeight
Gets or sets the thickness of the horizontal scroll bar.
- Value
- The height of the bar in whole logical pixels (1/96 inch). The default style sets
18; the value registered on the property is42.
Remarks
The thumb is as tall as the bar, and the arrow buttons, when shown, are square at this
size. HorizontalScrollBarMinHeight overrides it when larger.
See also
HorizontalScrollBarMinHeight
Gets or sets a height the horizontal scroll bar is never made thinner than.
- Value
- A height in whole logical pixels (1/96 inch). The default is
0: no minimum, soHorizontalScrollBarHeightalone decides the thickness.
Remarks
When larger than HorizontalScrollBarHeight it wins. It is useful where the
height is bound to something that can shrink – a zoom level or a density setting – and the bar must
stay large enough to grab.
IsHorizontalLineScrollerVisualsAvailable
Gets or sets whether the horizontal scroll bar has arrow buttons at its ends that scroll a little way left or right at each click.
- Value
trueto show the buttons. The default isfalse: the bar has only a track and a thumb.
Remarks
The buttons are square, each as wide as HorizontalScrollBarHeight, and repeat
while held down. Their colours are the LineScroller* brushes, such as
LineScrollerOnNormalBackgroundBrush and LineScrollerArrowFillBrush.
See also
IsVerticalLineScrollerVisualsAvailable
Gets or sets whether the vertical scroll bar has arrow buttons at its ends that scroll a little way up or down at each click.
- Value
trueto show the buttons. The default isfalse: the bar has only a track and a thumb.
Remarks
The buttons are square, each as tall as VerticalScrollBarWidth, and repeat
while held down. Their colours are the LineScroller* brushes, such as
LineScrollerOnNormalBackgroundBrush and LineScrollerArrowFillBrush.
See also
LineScrollerArrowFillBrush
Gets or sets the colour of the small triangle drawn on each arrow button.
- Value
- The default is
Brushes.White.
Remarks
The same colour is used in every state, so pick one that reads against all three button fills.
See also
LineScrollerOnMouseOverBackgroundBrush
Gets or sets the fill of an arrow button while the pointer is over it.
- Value
- The default is
Brushes.Red.
See also
LineScrollerOnMouseOverBorderBrush
Gets or sets the colour of the outline round an arrow button while the pointer is over it.
- Value
- The default is
Brushes.Orange.
See also
LineScrollerOnNormalBackgroundBrush
Gets or sets the fill of each arrow button while the pointer is not over it.
- Value
- The default is
Brushes.Green.
Remarks
The arrow itself is drawn with LineScrollerArrowFillBrush. Arrow buttons are
shown only when IsVerticalLineScrollerVisualsAvailable or
IsHorizontalLineScrollerVisualsAvailable is on.
See also
LineScrollerOnNormalBorderBrush
Gets or sets the colour of the one-pixel outline round each arrow button while the pointer is not over it.
- Value
- The default is
Brushes.LightGreen.
Remarks
Arrow buttons are shown only when IsVerticalLineScrollerVisualsAvailable or
IsHorizontalLineScrollerVisualsAvailable is on.
See also
LineScrollerOnPressedBackgroundBrush
Gets or sets the fill of an arrow button while it is held down.
- Value
- The default is
Brushes.White.
Remarks
Choose a colour that the arrow (LineScrollerArrowFillBrush) still shows
against: with the defaults, a white arrow on this white fill disappears while the button is
held.
See also
LineScrollerOnPressedBorderBrush
Gets or sets the colour of the outline round an arrow button while it is held down.
- Value
- The default is
Brushes.Black.
See also
ShouldOverlayContent
Gets or sets whether the scroll bars float over the content rather than taking room of their own beside it.
- Value
trueto draw the bars over the content. The default isfalse: the bars sit in a column and a row of their own, as in a standardScrollViewer.
Remarks
Overlaid, the content keeps the full width and height of the viewer, so it does not reflow
when a bar appears or disappears. Use thin bars (see VerticalScrollBarWidth) and a
transparent TrackBackgroundBrush so the content shows round the thumb, and leave some
padding at the right of the content so that the bar does not cover text.
Example
<sv:ExtendedScrollViewer ShouldOverlayContent="True"
VerticalScrollBarWidth="6"
TrackBackgroundBrush="Transparent" />ThumbCornerRadius
Gets or sets how far the corners of the scroll bars' thumbs are rounded.
- Value
- The radius of each corner in logical pixels (1/96 inch). The default is
50on every corner, which rounds any thumb thinner than 100 pixels into a pill.
Remarks
A radius larger than half the thumb's thickness gives fully rounded ends. Use 0 for
square thumbs, or a radius of about a quarter of the bar's thickness for slightly softened
corners.
ThumbOnMouseOverBackgroundBrush
Gets or sets the colour of a scroll bar's thumb while the pointer is over it.
- Value
- The default is
Brushes.Red.
See also
ThumbOnNormalFillBrush
Gets or sets the colour of the scroll bars' thumbs while the pointer is not over them.
- Value
- The default is
Brushes.LightBlue.
See also
ThumbOnPressedBackgroundBrush
Gets or sets the colour of a scroll bar's thumb while it is being dragged.
- Value
- The default is
Brushes.White.
See also
TrackBackgroundBrush
Gets or sets the colour of the scroll bars' tracks – the channel the thumb slides along.
- Value
- The default is a half-transparent silver (
#7FBFBFBF), so the content behind shows faintly when the bars float over it.
Remarks
Set it to Brushes.Transparent for bars that are only a thumb, which suits
ShouldOverlayContent. The track still answers clicks, which page through the content.
VerticalScrollBarMinWidth
Gets or sets a width the vertical scroll bar is never made thinner than.
- Value
- A width in whole logical pixels (1/96 inch). The default is
0: no minimum, soVerticalScrollBarWidthalone decides the thickness.
Remarks
When larger than VerticalScrollBarWidth it wins. It is useful where the
width is bound to something that can shrink – a zoom level or a density setting – and the bar must
stay large enough to grab.
VerticalScrollBarWidth
Gets or sets the thickness of the vertical scroll bar.
- Value
- The width of the bar in whole logical pixels (1/96 inch). The default style sets
18; the value registered on the property is42.
Remarks
The thumb is as wide as the bar, and the arrow buttons, when shown, are square at this
size. Thin bars of 6 to 10 pixels suit ShouldOverlayContent; 30 pixels or more suit a
touch screen. VerticalScrollBarMinWidth overrides it when larger.
See also
Fields
HorizontalScrollBarHeightProperty static
Identifies the HorizontalScrollBarHeight dependency property.
HorizontalScrollBarMinHeightProperty static
Identifies the HorizontalScrollBarMinHeight dependency property.
IsHorizontalLineScrollerVisualsAvailableProperty static
Identifies the IsHorizontalLineScrollerVisualsAvailable dependency property.
IsVerticalLineScrollerVisualsAvailableProperty static
Identifies the IsVerticalLineScrollerVisualsAvailable dependency property.
LineScrollerArrowFillBrushProperty static
Identifies the LineScrollerArrowFillBrush dependency property.
LineScrollerOnMouseOverBackgroundBrushProperty static
Identifies the LineScrollerOnMouseOverBackgroundBrush dependency property.
LineScrollerOnMouseOverBorderBrushProperty static
Identifies the LineScrollerOnMouseOverBorderBrush dependency property.
LineScrollerOnNormalBackgroundBrushProperty static
Identifies the LineScrollerOnNormalBackgroundBrush dependency property.
LineScrollerOnNormalBorderBrushProperty static
Identifies the LineScrollerOnNormalBorderBrush dependency property.
LineScrollerOnPressedBackgroundBrushProperty static
Identifies the LineScrollerOnPressedBackgroundBrush dependency property.
LineScrollerOnPressedBorderBrushProperty static
Identifies the LineScrollerOnPressedBorderBrush dependency property.
ShouldOverlayContentProperty static
Identifies the ShouldOverlayContent dependency property.
ThumbCornerRadiusProperty static
Identifies the ThumbCornerRadius dependency property.
ThumbOnMouseOverBackgroundBrushProperty static
Identifies the ThumbOnMouseOverBackgroundBrush dependency property.
ThumbOnNormalFillBrushProperty static
Identifies the ThumbOnNormalFillBrush dependency property.
ThumbOnPressedBackgroundBrushProperty static
Identifies the ThumbOnPressedBackgroundBrush dependency property.
TrackBackgroundBrushProperty static
Identifies the TrackBackgroundBrush dependency property.
VerticalScrollBarMinWidthProperty static
Identifies the VerticalScrollBarMinWidth dependency property.
VerticalScrollBarWidthProperty static
Identifies the VerticalScrollBarWidth dependency property.