Magnetic Effect In Slider

安稳与你 提交于 2019-12-24 14:52:46

问题


look i have Slider in Silverlight having maximum value of 1 starting from minimum value of 0,

i want the slider to have some magnetic effect, like if i drop slider thumb near 0 it must return to 0.

for example , if i drop the thumb between (0 - 0.50) say 0.40 the very thumb must move to 0, and if thumb drop at value more than 0.50 it must move to 1.

<Slider Height="50" x:Name="slider" Width="160"  Maximum="1" SmallChange="1" LargeChange="1" Minimum="0" />

回答1:


What about the ValueChanged-Event?

Build in something like this:

slider.Value = slider.Value <= 0.5 ? 0 : 1;



回答2:


public class SnappySlider : Slider
{
    public SnappySlider()
    {
        this.DefaultStyleKey = typeof(Slider);
    }

    protected override void OnValueChanged(double oldValue, double newValue)
    {
        base.OnValueChanged(oldValue, newValue);
        Value = Value < 0.5 ? 0 : 1;
    }
}


来源:https://stackoverflow.com/questions/8576429/magnetic-effect-in-slider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!