开发者

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&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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜