WP7 clamps and scales image in DataTemplate

I looked at this ping / zoom example and it seems pretty straight forward.

The problem is that my image is part of the data template of my control and I cannot 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>

This method transformcannot be enabled.

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

any ideas

thank!

+3
source share
1 answer

The sender must be the image to which the listener is connected:

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

initialAngle = transform.Rotation;
initialScale = transform.ScaleX;
+1
source

Source: https://habr.com/ru/post/1794827/


All Articles