Windows Phone 7 development

Simple center zoom

To add simple pinch zoom (that I used in my Spirit Level) use the Silverlight Toolkit for WP7 and add the pinch GetureListener to a grid

<toolkit:GestureService.GestureListener>
  <toolkit:GestureListener PinchDelta="GestureListener_PinchDelta" />
 </toolkit:GestureService.GestureListener>

and code in event

 private void GestureListener_PinchDelta(object sender, PinchGestureEventArgs e)
 {
    if (e.DistanceRatio < 1.0 || e.DistanceRatio > 1.4)
    {
      return;
    }
 // Create the animation for pinch
   Storyboard storyboard = new Storyboard();
   DoubleAnimation pinchXAnimation = new DoubleAnimation();
   pinchXAnimation.To = e.DistanceRatio;
   pinchXAnimation.Duration = TimeSpan.FromSeconds(0.3);
   storyboard.Children.Add(pinchXAnimation);
   Storyboard.SetTargetProperty(pinchXAnimation, new PropertyPath("GridScaling.ScaleX"));
   Storyboard.SetTarget(pinchXAnimation, GridScaling);

   DoubleAnimation pinchYAnimation = new DoubleAnimation();
   pinchYAnimation.To = e.DistanceRatio;
   pinchYAnimation.Duration = TimeSpan.FromSeconds(0.3);
   storyboard.Children.Add(pinchYAnimation);
   Storyboard.SetTargetProperty(pinchYAnimation, new PropertyPath("GridScaling.ScaleY"));
   Storyboard.SetTarget(pinchYAnimation, GridScaling);

   storyboard.Begin();

}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: