WPF Slider Example: ValueChanged event, minimum and maximum

October 14, 2015 0 Comments

Slider : It means slide the button from left to right or vise versa. When we slide it then we can do some changes in other things like change background color etc. WPF slider control have two public properties, first one is minimum and second one is maximum. Slider works from minimum to maximum also depends on user condition.

Example :  Drag and drop a slider control on WPF design window with two attributes, which are:
  • Minimum: get or set the minimum value of the control. By default it is zero.
  • Maximum: get or set the maximum value of the control. By default it is Ten.
Now after drag the control, your xaml code look like:

<Slider Name="slider" Minimum="0" Maximum="100" Value="25" Height="25" Width="300">

Run the code and the slider control is on your screen, with value 25- defined above.

Slider control WPF

Ticks can be used to place the slider on exact position. We can enable ticks by using the property TickPlacement. It have four values i.e. None, Both, TopLeft and BottomRight.
  • None: it will give a simple look as in above image. 
  • TopLeft: the ticks will placed on left with vertical orientation and top with horizontal. 
  • BottomRight: the ticks will placed on right with vertical orientation and bottom with horizontal.
  • Both: It is used on both left and right, when the orientation is vertical.
The following image shows the slider control with TickPlacement set to TopLeft.

Slider control with TickPlacement in WPF

Jacob Lefore

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google