滑块中的磁效应

发布于 2024-12-22 00:09:06 字数 314 浏览 3 评论 0原文

看看我在 Silverlight 中的滑块的最大值为 1,从最小值 0 开始,

我希望滑块具有一些磁效应,就像如果我将滑块拇指放在 0 附近,它必须返回到 0。

例如,如果我放下拇指在 (0 - 0.50) 之间,比如说 0.40,拇指必须移动到 0,如果拇指下降的值超过 0.50,它必须移动到 1。

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

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" />

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

耳钉梦 2024-12-29 00:09:06

ValueChanged 事件怎么样?

建立这样的东西:

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

What about the ValueChanged-Event?

Build in something like this:

slider.Value = slider.Value <= 0.5 ? 0 : 1;
各自安好 2024-12-29 00:09:06
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;
    }
}
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;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文