WPF - Controls- Slider - Windows Presentation Foundation(WPF)

What is WPF Slider?

A slider is a control with the help of which a user can select from a range of values by moving a Thumb control along a track. The hierarchical inheritance of Slider class is as follows −

hierarchy_of_slider (1)

Commonly Used Properties of Slider

Given below are the most commonly used properties of Slider.

r. No. Property & Description
1
Header
Gets or sets the content for the control's header.
2
HeaderProperty
Identifies the Header dependency property.
3
HeaderTemplate
Gets or sets the DataTemplate used to display the content of the control's header.
4
HeaderTemplateProperty
Identifies the HeaderTemplate dependency property.
5
IntermediateValue
Gets or sets the value of the Slider while the user is interacting with it, before the value is snapped to either the tick or step value. The value the Slider snaps to is specified by the SnapsTo property.
6
IntermediateValueProperty
Identifies the IntermediateValue dependency property.
7
IsDirectionReversed
Gets or sets a value that indicates the direction of increasing value.
8
IsDirectionReversedProperty
Identifies the IsDirectionReversed dependency property.
9
IsThumbToolTipEnabled
Gets or sets a value that determines whether the slider value is shown in a tool tip for the Thumb component of the Slider.
10
IsThumbToolTipEnabledProperty
Identifies the IsThumbToolTipEnabled dependency property.
11
Orientation
Gets or sets the orientation of a Slider.
12
OrientationProperty
Identifies the Orientation dependency property.
13
StepFrequency
Gets or sets the value part of a value range that steps should be created for.
14
StepFrequencyProperty
Identifies the StepFrequency dependency property.
15
ThumbToolTipValueConverter
Gets or sets the converter logic that converts the range value of the Slider into tool tip content.
16
ThumbToolTipValueConverterProperty
Identifies the ThumbToolTipValueConverter dependency property.
17
TickFrequency
Gets or sets the increment of the value range that ticks should be created for.
18
TickFrequencyProperty
Identifies the TickFrequency dependency property.
19
TickPlacement
Gets or sets a value that indicates where to draw tick marks in relation to the track.
20
TickPlacementProperty
Identifies the TickPlacement dependency property.

Commonly Used Events in Slider Class

Given below are the most commonly used events of Slider.

Sr. No. Event & Description
1
ManipulationCompleted
Occurs when a manipulation on the UIElement is complete. (Inherited from UIElement)
2
ManipulationDelta
Occurs when the input device changes position during a manipulation. (Inherited from UIElement)
3
ManipulationInertiaStarting
Occurs when the input device loses contact with the UIElement object during a manipulation and inertia begins. (Inherited from UIElement)
4
ManipulationStarted
Occurs when an input device begins a manipulation on the UIElement. (Inherited from UIElement)
5
ManipulationStarting
Occurs when the manipulation processor is first created. (Inherited from UIElement)
6
ValueChanged
Occurs when the range value changes. (Inherited from RangeBase)

Commonly Used Methods in Slider Class

Given below are the most commonly used methods of Slider.

Sr. No. Method & Description
1
OnManipulationCompleted
Called before the ManipulationCompleted event occurs. (Inherited from Control)
2
OnManipulationDelta
Called before the ManipulationDelta event occurs. (Inherited from Control)
3
OnManipulationInertiaStarting
Called before the ManipulationInertiaStarting event occurs. (Inherited from Control)
4
OnManipulationStarted
Called before the ManipulationStarted event occurs. (Inherited from Control)
5
OnManipulationStarting
Called before the ManipulationStarting event occurs. (Inherited from Control)
6
OnMaximumChanged
Called when the Maximum property changes. (Inherited from RangeBase)
7
OnMinimumChanged
Called when the Minimum property changes. (Inherited from RangeBase)
8
OnValueChanged
Fires the ValueChanged routed event. (Inherited from RangeBase)
9
SetBinding
Attaches a binding to a FrameworkElement, using the provided binding object. (Inherited from FrameworkElement)
10
SetValue
Sets the local value of a dependency property on a DependencyObject. (Inherited from DependencyObject)
Example

  • Let’s create a new WPF project with the name WPFDialog.
  • Drag one slider and two text blocks from the Toolbox.
  • Change the background color from the properties window.
  • The following example shows the usage of Slider in an XAML application. The following XAML code creates a Slider and text blocks and initializes them with some properties and events.

Here is the implementation in C# for Value Changed event.

When you compile and execute the above code, it will produce the following output −

output_of_slider (1)

We recommend that you execute the above example code and try the other properties and events of Slider class.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Windows Presentation Foundation(WPF) Topics