最低和最低最大逻辑

时间:2014-08-20 17:02:00

标签: c# wpf

我在使用WPF可缩放画布库时遇到问题,该库工作顺利,但无论我尝试什么,我都无法设置缩放的最小值或最大值(缩放),它可以缩放(缩放)或缩小尽可能没有任何限制,我该如何设置限制?例如,缩放不应小于1且大于5。

这是我在下面使用的代码:

    void PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
    {
        var x = Math.Pow(2, e.Delta / 3.0 / System.Windows.Input.Mouse.MouseWheelDeltaForOneLine);
        MyCanvas.Scale *= x;
        // Adjust the offset to make the point under the mouse stay still.
        var position = (System.Windows.Vector)e.GetPosition(basecan);
        MyCanvas.Offset = (System.Windows.Point)((System.Windows.Vector)
            (MyCanvas.Offset + position) * x - position);
        e.Handled = true;
    }

我花了好几个小时试图让它工作,谢谢你的帮助。

Here is the library

1 个答案:

答案 0 :(得分:1)

为什么不将比例缩小到极限?

class XXX{
    double scale = 1;
    public void PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e){
        this.scale *= Math.Pow(2, e.Delta / 3.0 / System.Windows.Input.Mouse.MouseWheelDeltaForOneLine);
        if (this.scale > 5) this.scale = 5;
        else if (this.scale < 1) this.scale = 1;
        MyCanvas.Scale = this.scale;
    }
}