开发者

How a Slider control in WPF can snap on specific values?

开发者 https://www.devze.com 2023-03-29 13:31 出处:网络
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 ma开发者_运维知识库ke easy

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 ma开发者_运维知识库ke 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...


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号