Silverlight 滑块及其拇指的精度问题

发布于 2024-12-07 16:12:54 字数 796 浏览 0 评论 0原文

我在 Silverlight 中的滑块控件上遇到了精度问题:

我构建了一些自定义模板来稍微修改标准 Silverlight 滑块控件的视觉外观。我的目标是拥有一个滑块,将其值表示为在其刻度上绘制的刻度。相应的拇指在形式上也略有修改,它的中心有一个“尖端”(或“峰值”),指向滑块的当前值。

-->这是它的快照: http://www.willzeit.at/sliderThumb.jpg

实际上一切正常,但我遇到了拇指的一个非常奇怪的行为:

拇指上指向滑块当前值的位置似乎从拇指上最左边的位置更改为拇指上最右边的位置!

因此,在拇指位于相对于滑块的最左侧位置的情况下,拇指上指向滑块值的点是拇指上的最左位置。

当然,如果拇指位于其最右侧位置且拇指上的值指示位置位于其最右侧位置,则同样成立。

当然,这是有道理的,因为拇指无法超出其滑块的边界,因此拇指上的“值指示”点必须在拇指的整个宽度范围内(在水平滑块的情况下)就像我的例子一样)。

但是:拇指和滑块之间的“同步”精度会显着下降(当然,只有当您想用拇指指示滑块的确切值时。

正如我所说,我需要构建一个显示值的滑块(当用户想要使用滑块控件设置特定值时,他必须以“针”停留在该特定值下方的方式移动拇指

。希望我能做到这个问题很清楚,也是我的问题:) 有人有什么想法吗? 我想一定有办法解决这个问题 - 否则滑块控件不打算以这种方式使用 - 这对我来说听起来不太可能......

我真的很感激任何帮助:) 马克

I have a precision problem with the slider control in Silverlight:

I've built some custeom template to slightly modify the visual appreance of the standard Silverlight slider control. My goal is to have a slider that represents it's values as drawn ticks on it's scale. The corresponding thumb is also slightly modified in the form, that it has a 'tip' (or 'peak') at it's very center to point at the current value at the slider.

--> Here's a snapshot it: http://www.willzeit.at/sliderThumb.jpg

Actually everything works, but I've encountered a very strange behavior of the thumb:

The position on the thumb that points to the current value at the slider seems to change from the left-most position on the thumb to the right-most position on the thumb!

So in the case the thumb is located at it's left-most position with respect to the slider the point on the thumb pointing to the slider-value is the left_most position on the thumb.

Of course the same holds if the thumb is at it's right-most position where the value-indicating position on the thumb is at it's right most position.

Of course that makes sense because the thumb won't be able to go beyond the boundaries of it's slider and therefor the 'value-indication' point on the thumb has to range over the whole width of the thumb (in case of an horizontal slider as in my case).

BUT: That's a significant loss of precision in the 'syncronization' between thumb and slider (of course only when you want to indicate the exact value of the slider with the thumb.

As i said, i need to build a slider that presents values (shown with ticks and labels) and a thumb with a needle. When the user wants to set a particular value with the slider control, he has to move the thumb in the way that it's 'needle' comes to rest beneath this particular value.

I hope i could make this issue clear and also my problem :)
Does anybody have any ideas ?
I guess there must be a way to solve this problem - otherwise the slider control is not intended to be used in such a way - what sounds highly unlikely for me ...

I really would appreciate any help :)
marc

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

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

发布评论

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

评论(1

锦爱 2024-12-14 16:12:54

理论上您所需要的只是让 Silder 控件认为它的拇指只有 1 像素宽。您可以通过修改 Thumb 模板来实现此目的,使模板中的顶部元素为 Canvas(网格剪辑其内容),然后将其余内容包含在 Grid 中code> 指定特定的大小,然后偏移其左边缘。使用奇数作为宽度并设置其左侧位置 = -1 * (Width -1) / 2。您可以通过边距、画布左侧或渲染变换来完成此操作。

现在我说“理论上”是因为在实践中我遇到了一个我无法解释的异常现象。无论我多么努力,只有拇指的左手侧是活动的。 Silverlight 似乎并不想识别拇指的右手侧。

最终我决定提出这个答案,因为显然您已经在编辑控制模板,也许如果您将其应用到您自己的工作中,您就不会出现这种异常情况。

Theoretically all you need is to make the Silder control think that its thumb is only 1 pixel wide. You can do this by modifying the Thumb template so that the top element in the template is a Canvas (a Grid clips its contents) and then contain the rest of the content in a Grid that you give a specific size to and then offset its left edge. Use an odd number for the width and set its left position = -1 * (Width -1) / 2. You can do this with margin, canvas left or a render transform.

Now I say "Theoretically" because in practice I've come across an anomoly that I just can't explain. No matter how hard I try only the Left hand side of the thumb is active. Silverlight just does not seem to want to recognise the right hand side of the thumb.

Ultimately I decided to put this answer out because clearly you are already editing the templates for control and perhaps if you apply it to your own work you won't get this anomoly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文