如何创建具有非线性标尺的滑块?标尺、滑块

由网友(夜长梦多、我脱了你随意)分享简介:我为0的最小值和最大值为500的滑块I have a slider with a minimum value of 0 and maximum of 500.欲当滑块前进到100,拇指处于滑块中间I want to when the slider goes to 100, the thumb be in the...

我为0的最小值和最大值为500的滑块

I have a slider with a minimum value of 0 and maximum of 500.

欲当滑块前进到100,拇指处于滑块中间

I want to when the slider goes to 100, the thumb be in the middle of the slider.

我知道这看起来奇怪,但一些方案,缩放滑块做到这一点,我相信这是更好的。

I know it seems wierd, but some programs do it with zoom slider, and I believe it's better.

推荐答案

这是这样一个有趣的问题,我不能息事宁人,希望我把你要问什么样的权利:)

This was such an interesting question that I couldn't leave it alone, and hopefully I got what you're asking right :)

您想要更改的 A 滑块从线性到二次函数通过指定的Y值该功能时,拇指在中间。

You want to change the Value of a Slider from Linear to a Quadratic Function by specifying the Y value of the function when the Thumb is in the middle.

有一个二次函数写在表 -

A Quadratic Function is written on the form

由于我们有3点,我们有3套值的X和Y

Since we have 3 points, we have 3 sets of values for X and Y.

(X1, Y1) = 0, 0  
(X2, Y2) = MiddleX, CenterQuadraticValue (in your case 100)  
(X3, Y3) = Maximum, Maximum (in your case 500)

从这里,我们可以创建一个二次方程(看到此链接,例如),它出来到< BR>

From here, we can create a Quadratic Equation (see this link for example) which comes out to

不幸的是,在该曲线图中的某些值最终低于0所以他们将不得不被强制为0(Ⅰ包括在答复的底部的曲线图)。的

我创建了一个控制, QuadraticSlider ,这源于滑块,并增加了两个依赖属性: QuadraticValue CenterQuadraticValue 。它计算 QuadraticValue 使用上述基于最大公式最小 CenterQuadraticValue 。这也正好相反:设置 QuadraticValue 更新。因此,而不是绑定到,结合到 QuadraticValue

I created a control, QuadraticSlider, which derives from Slider and adds two Dependency Properties: QuadraticValue and CenterQuadraticValue. It calculates QuadraticValue using the formula above based on Value, Maximum, Minimum and CenterQuadraticValue. It also does the reverse: setting QuadraticValue updates Value. So instead of Binding to Value, bind to QuadraticValue.

编辑:的最后一个版本是一个小马车。修正了一些事情

The last version was a little buggy. Fixed a couple of things

计算 QuadraticValue 不再休息时,a是0 从当导数是负二度解决方案中使用错误的根 Calculating Value from QuadraticValue no longer breaks when "a" is 0 Used wrong root from the second degree solution when the derivate was negative

我上传的,其中 QuadraticSlider 用来放大图片的示例应用程序。所有parameteres可以指定和第一画面使用和其他 QuadraticValue

I uploaded a sample application where QuadraticSlider is used to zoom a picture. All parameteres can be specified and the first picture uses Value and the other QuadraticValue.

如果你想尝试一下在这里下载。

它看起来像这样

It looks like this

这是图的样子,注意值低于0 的

阅读全文

相关推荐

最新文章