如何实现接受超过 100% 的值的 OpacityConverter ?比如 120% 或 150%。
谢谢。
I think you should adjust your code instead. Before providing your value to the converter, run it through Math.Min/Max
:
//adjusted = Max(0, Min(1.0, input))
decimal stuff1 = 1.1m;
decimal stuff2 = -0.1m;
decimal stuff3 = 0.5m;
decimal correct1 = Math.Max(0m, Math.Min(1.0m, stuff1)); // 1.0
decimal correct2 = Math.Max(0m, Math.Min(1.0m, stuff2)); // 0.0
decimal correct3 = Math.Max(0m, Math.Min(1.0m, stuff3)); // 0.5
Any opacity below 0% or above 100% doesn't make any sense, simply because you can't make anything more visible than fully visible; and likewise, you can't make something less visible than not visible.