Search code examples
wpfcontrolsslider

How do you make a WPF slider snap only to discrete integer positions?


All too often I want a WPF Slider control that behaves like the System.Windows.Forms.TrackBar of old. That is, I want a slider that goes from X to Y but only allows the user to move it in discrete integer positions.

How does one do this in WPF since the Value property on the Slider is double?


Solution

  • If you set your tick marks in the right way, you can use IsSnapToTickEnabled. This worked pretty well for me. See MSDN for details.