How can I make a XAML Slider element snap to allowed values only?
slider, wpf, xaml
Solution
Set the `IsSnapToTickEnabled` to `true` and assign a value of 1 to the `TickFrequency` property:
<Slider IsSnapToTickEnabled="True"
Maximum="1" />
Problem
I have a slider with minimum value 0 and maximum value 1. When I currently slide it, the value gets set to a decimal value between 0 and 1, e.g. 0.2342343. However, I want the value to only be either 0 or 1 (so that my ViewModel property will register the change only if it is 0 or 1 and not multiple times as the user drags it from 0 to 1). How can I make the slider value only be 0 or 1? I tried SmallChange, LargeChange and SnapsToDevicePixels, but none of these work. ``` <Slider Name="TheLanguageIndexSlider" DockPanel.Dock="Bottom" Minimum="0" Maximum="1" LargeChange="1" SmallChange="1" SnapsToDevicePixels="True" Width="100" Margin="5" Value="{Binding LanguageIndex}" HorizontalAlignment="Left"/> ```