开发者

WP7 pinch and zoom image in DataTemplate

开发者 https://www.devze.com 2023-02-13 07:11 出处:网络
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 acce

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&q开发者_如何学Gouot; 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!


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;
0

精彩评论

暂无评论...
验证码 换一张
取 消