如何设置限制图像缩放wp8?

时间:2015-02-24 06:11:48

标签: c# xaml windows-phone-8 zoom limit

我想设置缩放限制,以便在一定程度的缩放图像后不应进一步缩放。这是我的代码。

    private void OnPinchDelta(object sender, PinchGestureEventArgs e)
    {
        if (transform.ScaleX== 1)
        {
        }
        else
        {
            transform.Rotation = angle + e.TotalAngleDelta;
            transform.ScaleX = scale * e.DistanceRatio;
            transform.ScaleY = scale * e.DistanceRatio;
        }
    }

在一定程度的缩放后,图像被禁用。任何人都可以建议我如何限制此缩放。 提前谢谢。

2 个答案:

答案 0 :(得分:0)

只需声明最大值并将其与新比例进行比较。这是我的榜样:

private readonly double maxScale = 5;

private void OnPinchDelta(object sender, PinchGestureEventArgs e)
{
    if (transform.ScaleX == 1)
    {
    }
    else
    {
        transform.Rotation = angle + e.TotalAngleDelta;
        double newScale = scale * e.DistanceRatio;
        if (newScale > maxScale)
            newScale = maxScale;
        transform.ScaleX = newScale;
        transform.ScaleY = newScale;
    }
}

答案 1 :(得分:0)

最后有效的代码在这里。

private double maxScale =10; private double minScale =0.2; private void OnPinchDelta(object sender, PinchGestureEventArgs e) { transform.Rotation = angle + e.TotalAngleDelta; double newScale = scale * e.DistanceRatio; if (newScale > maxScale) newScale = maxScale; if (newScale < minScale) newScale = minScale; transform.ScaleX = newScale; transform.ScaleY = newScale; }