Export (0) Print
Expand All

How to: Customize the Ticks on a Slider

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

The TickBar displays when you set the TickPlacement property to a value other than None, which is the default value.

The following example shows how to create a Slider with a TickBar that displays tick marks. The TickPlacement and TickFrequency properties define the location of the tick marks and the interval between them. When you move the Thumb, tooltips display the value of the Slider. The AutoToolTipPlacement property defines where the tooltips occur. The Thumb movements correspond to the location of the tick marks because IsSnapToTickEnabled is set to true.

Slider hslider = new Slider();
hslider.Width = 100;
hslider.Orientation = Orientation.Horizontal;
hslider.IsSnapToTickEnabled = true;
hslider.Minimum = 1;
hslider.Maximum = 20;
hslider.TickPlacement = TickPlacement.Both;
hslider.TickFrequency = 2;
hslider.AutoToolTipPlacement =
  AutoToolTipPlacement.BottomRight;
cv1.Children.Add(hslider);
<Slider Name="slider1" 
        Width="100" 
        Orientation="Horizontal" HorizontalAlignment="Left" 
        IsSnapToTickEnabled="True" Minimum="1" Maximum="20" 
        TickPlacement="Both"  TickFrequency="2"
        AutoToolTipPlacement="BottomRight"/>

The following example shows how to use the Ticks property to create tick marks along the Slider at irregular intervals.

<Slider Width="100" Value="50" Orientation="Horizontal" HorizontalAlignment="Left" 
        IsSnapToTickEnabled="True" Maximum="3" TickPlacement="BottomRight" 
        AutoToolTipPlacement="BottomRight" AutoToolTipPrecision="2" 
        Ticks="0, 1.1, 2.5, 3"/>

For the complete sample, see Slider with Data Binding Sample.

Community Additions

ADD
Show:
© 2014 Microsoft