如何使 WPF 滑块仅吸附到离散的整数位置? [英] How do you make a WPF slider snap only to discrete integer positions?

查看:29
本文介绍了如何使 WPF 滑块仅吸附到离散的整数位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常想要一个 WPF 滑块,其行为类似于旧的 System.Windows.Forms.TrackBar.也就是说,我想要一个从 X 到 Y 的滑块,但只允许用户在离散的整数位置移动它.

All too often I want a WPF slider that behaves like the System.Windows.Forms.TrackBar of old. That is, I want a slider that goes from X to Y but only allows the user to move it in discrete integer positions.

如何在 WPF 中做到这一点,因为 Slider 上的 Value 属性是双倍的?

How does one do this in WPF since the Value property on the Slider is double?

推荐答案

如果您以正确的方式设置刻度线,则可以使用 IsSnapToTickEnabled.这对我来说效果很好.有关详细信息,请参阅 MSDN.

If you set your tick marks in the right way, you can use IsSnapToTickEnabled. This worked pretty well for me. See MSDN for details.

这篇关于如何使 WPF 滑块仅吸附到离散的整数位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆