earthling
earthling

Reputation: 5264

WP7 pinch and zoom image in DataTemplate

I've looked at this example of ping/zoom of images and seems pretty straight forward.

The problem I'm having is that my image is part of the data template of my pivot control and I am unable to access the transform object.

<DataTemplate>
    <Image Name="displayImage" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Source="{Binding photo_link}" RenderTransformOrigin="0.5, 0.5" CacheMode="BitmapCache">
        <Image.RenderTransform>
            <CompositeTransform x:Name="transform" />
        </Image.RenderTransform>
        <toolkit:GestureService.GestureListener>
            <toolkit:GestureListener PinchDelta="OnPinchDelta" PinchStarted="OnPinchStarted" />
        </toolkit:GestureService.GestureListener>
    </Image>
</DataTemplate>

In this method, transform cannot be resolved.

private void OnPinchStarted(object sender, PinchStartedGestureEventArgs e)
{
    initialAngle =  transform.Rotation;
    initialScale = transform.ScaleX;
}

any ideas??

thanks!

Upvotes: 3

Views: 2138

Answers (1)

Michael S. Scherotter
Michael S. Scherotter

Reputation: 10785

The sender should be the Image that the listener is attached to:

var image = sender as Image;
var transform = image.RenderTransform as CompositeTransform;

initialAngle = transform.Rotation;
initialScale = transform.ScaleX;

Upvotes: 1

Related Questions