Export (0) Print
Expand All

Slider Class

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

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

[LocalizabilityAttribute(LocalizationCategory.Ignore)] 
[TemplatePartAttribute(Name="PART_Track", Type=typeof(Track))] 
[TemplatePartAttribute(Name="PART_SelectionRange", Type=typeof(FrameworkElement))] 
public class Slider : RangeBase
/** @attribute LocalizabilityAttribute(LocalizationCategory.Ignore) */ 
/** @attribute TemplatePartAttribute(Name="PART_Track", Type=System.Windows.Controls.Primitives.Track) */ 
/** @attribute TemplatePartAttribute(Name="PART_SelectionRange", Type=System.Windows.FrameworkElement) */ 
public class Slider extends RangeBase
LocalizabilityAttribute(LocalizationCategory.Ignore) 
TemplatePartAttribute(Name="PART_Track", Type=System.Windows.Controls.Primitives.Track) 
TemplatePartAttribute(Name="PART_SelectionRange", Type=System.Windows.FrameworkElement) 
public class Slider extends RangeBase

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 descriptions and the Slider Overview.

The default value of the Maximum property is overridden by the Slider control class, as shown in the following table.

Property

BaseClass

Default

SubClass

Default

Maximum

RangeBase

1

Slider

10

This example shows how to create a horizontal Slider control

The following example shows how to create a horizontal Slider. In the code examples, the Slider is created as the child element of a Canvas (cv1).

<Slider Width="100" Value="0"
        Orientation="Horizontal" HorizontalAlignment="Left"/>
<Slider Width="100" Height="30" Value="0" Orientation="Vertical"/>

Slider hslider = new Slider();
hslider.Orientation = Orientation.Horizontal;
hslider.AutoToolTipPlacement =
  AutoToolTipPlacement.TopLeft;
hslider.AutoToolTipPrecision = 2;
hslider.IsDirectionReversed = true;
hslider.Width = 100;
hslider.IsMoveToPointEnabled = false;
hslider.SelectionStart = 1.1;
hslider.SelectionEnd = 3;
hslider.IsSelectionRangeEnabled = false;
hslider.IsSnapToTickEnabled = false;
hslider.TickFrequency = 3;
hslider.TickPlacement = TickPlacement.Both;
cv1.Children.Add(hslider);

For the complete sample, see Slider Sample.

More Code

How to: Create a Slider with a TickBar

This example shows how to create a Slider control that has tick marks.

How to: Bind a Property to a Slider Value

This example shows how to bind the Height property of a Rectangle to the Value of a Slider control.

System.Object
   System.Windows.Threading.DispatcherObject
     System.Windows.DependencyObject
       System.Windows.Media.Visual
         System.Windows.UIElement
           System.Windows.FrameworkElement
             System.Windows.Controls.Control
               System.Windows.Controls.Primitives.RangeBase
                System.Windows.Controls.Slider

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft