How a Slider control in WPF can snap on specific v

2019-04-14 04:02发布

I want to create a slider, with values from 0 to 100 that I can slide like any other slider... but at position 30, 42 and 55 (for example) I want to snap to these values, to make easy to the user to stop the slider at them

edit: my solution was to have 2 slider, the first one is invisible, value 0 to 200, and the other one is the visible on, value 0 to 100 The visible one cannot be slide, only the the invisible. Like this i can make a gap, ex: when I'm between 50 and 75 on the invisible slider, it's equals to 50 on the visible one...

1条回答
【Aperson】
2楼-- · 2019-04-14 04:59

You have to override OnValueChanged. See this article DiscreteSlider - Adding Functionality with a Simple Control Subclass and then this artice Silverlight slider control that snaps for a detailed explanation.

Instead of using SmallChange, you would check where between your values the slider sits and snap to the nearest.

查看更多
登录 后发表回答