Share via


How to: Create a Slider

This example shows how to create a horizontal Slider control

Example

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);
cv1.Children.Clear()
Dim hslider As New Slider()
hslider.Orientation = Controls.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.TickFrequency = 3
hslider.TickPlacement = TickPlacement.Both
hslider.Value = 0
cv1.Children.Add(hslider)

For the complete sample, see Slider Sample.

See Also

Reference

Slider

Concepts

Slider Overview

Other Resources

Slider How-to Topics
Slider Samples