#1,019 – Constraining a Slider to Integer Values
February 28, 2014 2 Comments
The Value property of a Slider can take on any value between the Minimum and Maximum values. Because it is of type double, it will normally take on a series of real number values as the user drags the thumb.
If you want to constrain the Slider values to be integer values only, you can set the following properties:
- TickFrequency : 1
- IsSnapToTickEnabled : True
Tickmarks will not be shown, but the Slider will now be constrained only to integer values.
<Slider Name="mySlider" Margin="10" Minimum="1" Maximum="100" TickFrequency="1" IsSnapToTickEnabled="True"/> <StackPanel Orientation="Horizontal"> <Label Content="Value:" VerticalAlignment="Center"/> <TextBlock Text="{Binding Path=Value, ElementName=mySlider}" Margin="10"/> </StackPanel>
Pingback: Dew Drop – February 28, 2014 (#1733) | Morning Dew
really cool