滑块取决于最小最大范围的行为 [英] Slider's behaviour depending on minimum-maximum range

查看:144
本文介绍了滑块取决于最小最大范围的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作在Windows Phone 8.1运行时和我遇到了奇怪的问题。

I'm working on Windows Phone 8.1 Runtime and I've encountered strange problem.

让我们定义两个几乎相同的 Silders

Let's define two almost identical Silders:

<Slider Header="Values 0.1-0.9" Grid.Row="0" HorizontalAlignment="Stretch" TickFrequency="0.05" TickPlacement="Inline"
        Minimum="0.1" Maximum="0.9" Value="0.2"/>
<Slider Header="Values 1.0-9.0" Grid.Row="1" HorizontalAlignment="Stretch" TickFrequency="0.5"  TickPlacement="Inline"
        Minimum="1" Maximum="9" Value="2"/>



正如你可以看到第二的滑块的从第一只由它分化范围(10次)。但事实证明,第一个不能正常工作(见附件图片) - 该值似乎是从0开始(以为你无法将它设定的最小0.1以下 - 你总是有从0小横轨)。

As you can see the second Slider differentiate from the first only by it's range (10 times). But it turns out that the first one is not working properly (see attached image) - the value seems to be starting from 0 (thought you cannot set it below the set minimum 0.1 - you always have little horizontal track from 0).

这似乎是一个小错误(可能与地方四舍五入的最小值),但也许我错过了一些东西。有没有一种方法,使其与工作价值低于1.0(不使用转换器)?

It seems to be a little bug (probably with rounding the minimum value somewhere?), but maybe I've missed something. Is there a way to make it work with values less than 1.0 (without using Converters)?

推荐答案

您已经在那里发现一个有趣的问题。 +1的提问。

An interesting problem you have found there. +1 for the question.

我检查我们的,它似乎内置滑块确实不能很好地工作时,最小和最大的不是整数。我能想到的3种方式工作,解决这个问题。

I checked it our and it seems the built-in Slider really doesn't work very well when Minimum and Maximum are not whole numbers. I can think of 3 ways to work-around this.

1。包装属性添加到VM类(我假设你要绑定的值,因为你提到的转换器)

1. Add wrapper Property to the VM class (I assume you want to bind the Value, since you mentioned Converters)

我们的想法是另一个属性添加到你绑定虚拟机是这样的:

The idea is to add another Property to the VM that you bind to like this:

//Lets assume that the original property that ranges from 0.1 to 0.9 is called MyProp
public double MyPropBinding {
    get {
        return this.MyProp * 10.0;
    }
    set {
        this.MyProp = value / 10.0;
    }
}

这基本上是相当简单,不需要任何额外的类,这是我与转换器的最大的问题。它可能不是完美的,如果你有需要做的10 VM类,虽然。

This is basically quite simple and requires no additional class, which is my biggest problem with converters. It may not be perfect if you have 10 VM classes that need to do it, though.

2。使用转换器

是的,我知道你问无需转换器的选择,但我想说的话,它实际上是一个非常好的选择。不超爽,因为你需要另一个类和更长的文本装订,但不需要任何研究。而时间是宝贵的!您可以基本解决在非哈克方式几分钟你的问题。

Yes, I know you asked for an option without a Converter, but I wanted to say that it is actually a very good option. Not super cool as you need another class and longer binding text, but does not require any research. And time is precious! You can basically solve your problem in a few minutes in a non-hacky way.

3。固定滑块(这种或那种方式)

我想你可以延长滑块和一些属性添加到它,那将修复它。例如:规模(这将是在您的案件10)和ValueScaled这将是价值/规模。所以,你会使用您的自定义滑块,最小值和最大值是1和9,规模将是10,你就会有ValueScaled这将是你真正想要的价值。

I think you could extend the Slider and add some properties to it, that will fix it. For example: Scale (that would be 10 in your case) and ValueScaled which would be Value / Scale. So you would be using your custom Slider, Min and Max would be 1 and 9, Scale would be 10 and you'll have ValueScaled which would be the value that you actually want.

PS 我没有研究了很多,因为我觉得这些至少有一个应该只是罚款为你(和其他人)。有可能是冷却器解决方案在那里。 :)

P.S. I haven't researched it a lot, because I think at least one of these should work just fine for you (and everyone else). There may be cooler solutions out there. :)

这篇关于滑块取决于最小最大范围的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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