如何移动图像Windows Phone 8

时间:2014-02-26 07:50:06

标签: c# windows-phone-8

如何使用句柄操作事件windows phone 8移动图像。 我尝试过使用ManipulationDelta,这是有效的,但是当我多次触摸图像时,它会返回翻译,大小。

private void RectangleImg_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
    Image Img = (Image)sender;
    var transform = (CompositeTransform)Img.RenderTransform;
    if (e.PinchManipulation == null)
    {                                
        transform.TranslateX += e.DeltaManipulation.Translation.X;
        transform.TranslateY += e.DeltaManipulation.Translation.Y;     
    }

    if (e.PinchManipulation != null)
    {
        transform.ScaleX = e.PinchManipulation.CumulativeScale;
        transform.ScaleY = e.PinchManipulation.CumulativeScale;
        transform.Rotation = angleBetween2Lines(e.PinchManipulation.Current,e.PinchManipulation.Original);
        e.Handled = true;
    }
}

public static double angleBetween2Lines(PinchContactPoints line1, PinchContactPoints line2)
{
    if (line1 != null && line2 != null)
    {
        double angle1 = Math.Atan2(line1.PrimaryContact.Y - line1.SecondaryContact.Y,
                                   line1.PrimaryContact.X - line1.SecondaryContact.X);
        double angle2 = Math.Atan2(line2.PrimaryContact.Y - line2.SecondaryContact.Y,
                                   line2.PrimaryContact.X - line2.SecondaryContact.X);
        return (angle1 - angle2) * 180 / Math.PI;
    }
    else { return 0.0; }
}

0 个答案:

没有答案