问题
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