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

查看:48
本文介绍了如何使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以来,如何在WPF中做到这一点?滑块上的Value属性是否为double?

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天全站免登陆