3
votes

I have windows phone silverlight 8.1 app. I want to zoom the image. Here is my code snippet. The issue is that it does not zoom on the place where pinch is performed. It always zoom in at top left corner of the image. Any help would be appreciated. Thanks

private void Image_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
    if (e.PinchManipulation != null)
    {
        var transform = (CompositeTransform)img.RenderTransform;

        // Scale Manipulation
        transform.ScaleX = e.PinchManipulation.CumulativeScale;
        transform.ScaleY = e.PinchManipulation.CumulativeScale;

        // Translate manipulation
        var originalCenter = e.PinchManipulation.Original.Center;
        var newCenter = e.PinchManipulation.Current.Center;
        transform.TranslateX = newCenter.X - originalCenter.X;
        transform.TranslateY = newCenter.Y - originalCenter.Y;

        e.Handled = true;
    }
}
2

2 Answers

0
votes

I think the best way to do this is to put Image in ScrollViewer in that way System Manipulation will do all zooming thing for free.

<ScrollViewer>
    <Image />
</ScrollViewer>

If it's not answer of your question ,let me know then i'll delete my post.

0
votes

You need to set transform.CenterX and transform.CenterY