Slider Class

Definition

Represents a control that lets the user select from a range of values by moving a Thumb control along a Track.

[System.Windows.Localizability(System.Windows.LocalizationCategory.Ignore)]
[System.Windows.TemplatePart(Name="PART_Track", Type=typeof(System.Windows.Controls.Primitives.Track))]
[System.Windows.TemplatePart(Name="PART_SelectionRange", Type=typeof(System.Windows.FrameworkElement))]
public class Slider : System.Windows.Controls.Primitives.RangeBase
Inheritance
Attributes

Inherited Members

System.Object

System.Windows.Controls.Control

System.Windows.Controls.Primitives.RangeBase

System.Windows.DependencyObject

System.Windows.FrameworkElement

System.Windows.Media.Visual

System.Windows.Threading.DispatcherObject

System.Windows.UIElement

Examples

The following examples shows how to bind the Height property of a Rectangle to the Value of a Slider control.

The following example defines a Slider control that is named RectangeHeight that can have a Value between 0 and 200.

<Slider Name="RectangleHeight"  Margin="10, 0, 0, 0" 
  Width="100" Orientation="Horizontal" HorizontalAlignment="Left" 
  Value="50" Minimum="0" Maximum="200" 
  SmallChange="1" LargeChange="10"
  TickPlacement="BottomRight" TickFrequency="10"/>

The following example shows how to define a Rectangle that binds its Height property to the Value of the Slider control. (In the complete sample, a similar binding is created for the Width property.)

<Rectangle Fill="Blue" HorizontalAlignment="Left" 
           Margin="50,20,0,0" 
           Height="{Binding ElementName=RectangleHeight,Path=Value}" 
           Width="{Binding ElementName=RectangleWidth,Path=Value}"/>

Remarks

A Slider control lets users select a value from a range of values. The following illustration shows an example of a Slider control.

Example of a Slider Control

Slider illustration

You can customize a Slider control by setting its properties. The following list describes some of the attributes of a Slider that you can customize:

  • The orientation of the Slider, either horizontal or vertical.

  • The tick mark locations along the Slider track.

  • The display of tooltips to show the current value of the Slider.

  • The ability of the Thumb to either snap to tick marks or to be positioned at any point along the Slider.

  • The direction of increasing value along the Slider.

For more information about how to customize a Slider control, see the individual member.

Slider overrides the metadata of the Maximum property and sets its default to 10. For more information, see Dependency Properties Overview.

Note

If the value of the Slider is animated, the user may no longer be able to interact with the Slider control after the animation finishes. See How to: Set a Property After Animating It with a Storyboard for options of how you can restore user control of a Slider after it is animated.

Customizing the Slider Control

To apply the same property settings to multiple Slider controls, use the Style property. You can modify the default ControlTemplate to give the control a unique appearance. For more information about creating a ControlTemplate, see Customizing the Appearance of an Existing Control by Creating a ControlTemplate. To see the parts and states that are specific to the Slider, see Slider Styles and Templates.

Dependency properties for this control might be set by the control’s default style. If a property is set by a default style, the property might change from its default value when the control appears in the application. The default style is determined by which desktop theme is used when the application is running. For more information, see Default WPF Themes.

Note

Setting a visual property will only have an effect if that property is both present in Slider control's default template and is set by using a . You can find a list of visual properties in the "Changing the Visual Structure of a Control" section in Customizing the Appearance of an Existing Control by Creating a ControlTemplate.

Constructors

Slider()

Initializes a new instance of the Slider class.

Fields

Auto​Tool​Tip​Placement​Property

Identifies the AutoToolTipPlacement dependency property.

Auto​Tool​Tip​Precision​Property

Identifies the AutoToolTipPrecision dependency property.

Delay​Property

Identifies the Delay dependency property.

Interval​Property

Identifies the Interval dependency property.

Is​Direction​Reversed​Property

Identifies the IsDirectionReversed dependency property.

Is​Move​To​Point​Enabled​Property

Identifies the IsMoveToPointEnabled dependency property.

Is​Selection​Range​Enabled​Property

Identifies the IsSelectionRangeEnabled dependency property.

Is​Snap​To​Tick​Enabled​Property

Identifies the IsSnapToTickEnabled dependency property.

Orientation​Property

Identifies the Orientation dependency property.

Selection​End​Property

Identifies the SelectionEnd dependency property.

Selection​Start​Property

Identifies the SelectionStart dependency property.

Tick​Frequency​Property

Identifies the TickFrequency dependency property.

Tick​Placement​Property

Identifies the TickPlacement dependency property.

Ticks​Property

Identifies the Ticks dependency property.

Properties

Auto​Tool​Tip​Placement

Gets or sets whether a tooltip that contains the current value of the Slider displays when the Thumb is pressed. If a tooltip is displayed, this property also specifies the placement of the tooltip.

Auto​Tool​Tip​Precision

Gets or sets the number of digits that are displayed to the right side of the decimal point for the Value of the Slider in a tooltip.

Decrease​Large

Gets a command that decreases the value of the Slider by the same amount as the LargeChange property.

Decrease​Small

Gets a command that decreases the value of the Slider by the same amount as the SmallChange property.

Delay

Gets or sets the amount of time in milliseconds that a RepeatButton waits, while it is pressed, before a command to move the Thumb executes, such as a DecreaseLarge command.

Increase​Large

Gets a command that increases the value of the slider by the same amount as the LargeChange property.

Increase​Small

Gets a command that increases the value of the slider by the same amount as the SmallChange property.

Interval

Gets or sets the amount of time in milliseconds between increase or decrease commands when a user clicks the RepeatButton of a Slider.

Is​Direction​Reversed

Gets or sets the direction of increasing value.

Is​Move​To​Point​Enabled

Gets or sets a value that indicates whether the Thumb of a Slider moves immediately to the location of the mouse click that occurs while the mouse pointer pauses on the Slider track.

Is​Selection​Range​Enabled

Gets or sets a value that indicates whether the Slider displays a selection range along the Slider.

Is​Snap​To​Tick​Enabled

Gets or sets a value that indicates whether the Slider automatically moves the Thumb to the closest tick mark.

Maximize​Value

Gets a command that sets the SliderValue to the Maximum value.

Minimize​Value

Gets a command that sets the SliderValue to the Minimum value.

Orientation

Gets or sets the orientation of a Slider.

Selection​End

Gets or sets the largest value of a specified selection for a Slider.

Selection​Start

Gets or sets the smallest value of a specified selection for a Slider.

Tick​Frequency

Gets or sets the interval between tick marks.

Tick​Placement

Gets or sets the position of tick marks with respect to the Track of the Slider.

Ticks

Gets or sets the positions of the tick marks to display for a Slider.

Methods

Arrange​Override(​Size)

Arranges the content of a Slider and determines its Size.

On​Apply​Template()

Builds the visual tree for the Slider control.

On​Create​Automation​Peer()

Creates an AutomationPeer for the Slider.

On​Decrease​Large()

Responds to the DecreaseLarge command.

On​Decrease​Small()

Responds to a DecreaseSmall command.

On​Increase​Large()

Responds to an IncreaseLarge command.

On​Increase​Small()

Responds to an IncreaseSmall command.

On​Maximize​Value()

Responds to the MaximizeValue command.

On​Maximum​Changed(​Double, ​Double)

Responds to a change in the value of the Maximum property.

On​Minimize​Value()

Responds to a MinimizeValue command.

On​Minimum​Changed(​Double, ​Double)

Responds to a change in the value of the Minimum property.

On​Preview​Mouse​Left​Button​Down(​Mouse​Button​Event​Args)

Provides class handling for the PreviewMouseLeftButtonDown routed event.

On​Thumb​Drag​Completed(​Drag​Completed​Event​Args)

Provides class handling for the DragCompleted event that occurs when the user stops dragging the Thumb of the Slider.

On​Thumb​Drag​Delta(​Drag​Delta​Event​Args)

Provides class handling for the DragDelta event that occurs when the user drags the Thumb of the Slider.

On​Thumb​Drag​Started(​Drag​Started​Event​Args)

Provides class handling for the DragStarted event that occurs when the user starts to drag the Thumb of the Slider.

On​Value​Changed(​Double, ​Double)

Updates the current position of the Slider when the Value property changes.