The Slider
is an interactive control that allows the user to set its Value
property by dragging or pressing the Slider
track. It is ideal for values that do not require a high level of precision, such as the volume setting for music in a game.
The following demonstrates how to define a Slider
in XAML:
<Slider Value="5" Minimum="0" Maximum="100" LargeChange="20" />
The Value
, Minimum
, and Maximum
properties are described in the previous section on the RangeBase
control.
When the user taps the Slider
track, the Value
property is incremented or decremented by the value of the LargeChange
property.
The default orientation of the Slider
is horizontal. The orientation can be changed by setting the Orientation
property to Vertical
.
The Slider
is an especially useful control on the Windows Phone platform, since the use of touch makes the slider easier to control than it would otherwise be with the mouse.
Note
The built-in Slider
control is, however, somewhat cumbersome to use. The control template for the Slider
was built for Silverlight for the Browser, where mice are better at hitting small targets. A number of custom templates are available on the Web that provide better usability. Dave Relyea, the lead developer of the Windows Phone Toolkit team, provides an improved Slider
control. See http://bit.ly/b0YtQj for more information.
Further examples of the Slider
control can be found throughout this book, such as in Chapter 14, “Leveraging Built-In Apps via Launchers and Choosers,” and in Chapter 17, “Building Location Aware Apps.”
Do not place a horizontal Slider
control on a Pivot
or Panorama
control. Doing so may interfere with a user’s ability to move between items, or it may prevent a user from manipulating the Slider
without moving between Panorama
or Pivot
items. This also applies to other controls like the Bing Maps control, which rely on the user performing a drag gesture.
You learn more about the Pivot
or Panorama
in Chapter 11.
Note that you may see a Slider
placed in a Pivot
in the sample code. This has been done for the sake of convenience and should not be taken as guidance.
3.144.40.189