Setting the Scrollbar Thumb size

Ash picture Ash · Jun 25, 2010 · Viewed 21.8k times · Source

I am attempting to work out the algorithm associated with sizing of the WPF Scrollbar thumb element.

The thumb element can be sized using the Scrollbar.ViewportSize property, but it in turn is related to the Scrollbar.Minimum and Scrollbar.Maximum values.

What I have discovered so far is:

For a Minimum and Maximum of 0 and 10, a ViewportSize of:

0 - Thumb minimum size
5 - Thumb approximately 25% of the available track
10 - Thumb approximately 50% of the available track
100 - Thumb approximately 75% of the available track
1000 - Thumb approximately 90% of the available track
10000 - Thumb fills the available track.

[note: these figures are only from my rough trial and error!]

Ideally I'd like to be able to have an algorithm where given the minimum and maximum values for the Scrollbar I can set the thumb size to be exactly x% of the available track.

Can anyone help with this?

Thanks.

Answer

Gavin S picture Gavin S · Sep 29, 2010

From: http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.track(VS.90).aspx

thumbSize = (viewportSize/(maximum–minimum+viewportSize))×trackLength

or re-arranging for viewportSize:

viewportSize = thumbSize×(maximum-minimum)/(trackLength-thumbSize)

You've prob found this already but thought I'd post in case others end up here.