Using the Slider control to pick a numeric value
The Slider
control is used to pick a numeric value by dragging a thumb button along a horizontal or vertical line. This is often used to provide a visualization of a playing video and as a volume indicator.
WPF provides us a control named Slider
to quickly implement this in your application UI, and, with a lot of properties for various configurations. Let's learn more about it, in this recipe.
Getting ready
First, create a project named CH02.SliderDemo
, based on the WPF application template.
How to do it...
Integration of the slider in WPF is very easy. Just place <Slider />
in your XAML page, and it will start working. But to customize it further, let's follow these steps:
- Open the
MainWindow.xaml
page, and replace the defaultGrid
with aStackPanel
. - Now add a
Slider
and aTextBlock
control inside theStackPanel
, as shown in the following XAML snippet:
<StackPanel Margin="10"> <Slider x:Name="slider" Minimum="0" Maximum...