Hi friends,
I want to know that how can we Zooming up and down the image using wp7?
Thanks
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Hemant KumarRank #1,202 · 1.5K reputationPosted Jan 11, 2012, 2:06 AM EST
If you don't want to use DeepZoom, you could also use a ViewBox to contain the Image, and listen for the pinch touch gestures/events and zoom in and out of the ViewBox using a RenderTransform.
Below is some code that I used for a Silverlight app, which with some work could be changed to react to Pinch and touch gestures instead of mousewheel + click/drag events. It might be possible to also change the amount of zoom depending on the "strength" of the pinch gesture.
For a viewbox defined in XAML:
Codebehind:
#region Pan and Zoom Events and Handlers void MouseClickHandler(object sender, MouseButtonEventArgs e) { _mouseClickPos = e.GetPosition(viewboxBackground); bMoving = true; } void MouseMoveHandler(object sender, MouseEventArgs e) { if (bMoving) { //get current transform CompositeTransform transform = viewboxMain.RenderTransform as CompositeTransform; Point currentPos = e.GetPosition(viewboxBackground); transform.TranslateX += (currentPos.X - _mouseClickPos.X); transform.TranslateY += (currentPos.Y - _mouseClickPos.Y); viewboxMain.RenderTransform = transform; _mouseClickPos = currentPos; } } void MouseReleaseHandler(object sender, MouseButtonEventArgs e) { bMoving = false; } void MouseWheelZoom(object sender, MouseWheelEventArgs e) { if (e.Delta > 0) { _zoomMultiplier += _zoomRate; ApplyZoomTransform(viewboxMain, _zoomMultiplier, new Point(viewboxMain.ActualWidth / 2, viewboxMain.ActualHeight / 2)); } else if (e.Delta 1) { _zoomMultiplier -= _zoomRate; ApplyZoomTransform(viewboxMain, _zoomMultiplier, new Point(viewboxMain.ActualWidth / 2, viewboxMain.ActualHeight / 2)); } } /// /// /// /// /// /// If provided, the zoom will be centered around the given position. void ApplyZoomTransform(UIElement element, double iZoomFactor, Point? zoomCenter) { //get current transform CompositeTransform transform = viewboxMain.RenderTransform as CompositeTransform; if (zoomCenter != null) { transform.CenterX = zoomCenter.GetValueOrDefault().X; transform.CenterY = zoomCenter.GetValueOrDefault().Y; } transform.ScaleX = iZoomFactor; transform.ScaleY = iZoomFactor; element.RenderTransform = transform; } #endregion http://stackoverflow.com/questions/4678268/how-to-zoom-in-and-zoom-out-images-in-wp7