Which control to use to display a larger image on Windows Phone 7

I would like to show a larger image on Windows Phone 7. I need to zoom in and out using multi-touch gestures. I was wondering if there is any control that can do this out of the box in the Windows Phone 7 SDK?

+3
source share
3 answers

If you do not want to use DeepZoom, you can also use the ViewBox to hold the image, and listen to a pinch of touch gestures / events and increase and decrease the ViewBox using RenderTransform.

Below is the code that I used for the Silverlight application, which with some work can be modified to respond to Pinch and touch gestures instead of mousewheel + click / drag events. It is also possible to change the zoom scale depending on the “strength” of the pinch gestures.

For the viewport defined in XAML:

    <Border Name="viewboxBackground" Background="Black">
            <Viewbox Name="viewboxMain">
                <!--your content here -->
            </Viewbox>
    </Border>   

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 < 0 && _zoomMultiplier > 1)
        {
            _zoomMultiplier -= _zoomRate;
            ApplyZoomTransform(viewboxMain, _zoomMultiplier, new Point(viewboxMain.ActualWidth / 2, viewboxMain.ActualHeight / 2));
        }
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="element"></param>
    /// <param name="iZoomFactor"></param>
    /// <param name="zoomCenter">If provided, the zoom will be centered around the given position.</param>
    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
+6
source

You may be interested in DeepZoom . Not sure how well it supports the multi-touch gesture out of the box, but you can learn about using gestures here and simulating multi-touch here if multi-touch support is not standard. Here is an example of a DeepZoom video on WP7 .

+2
source

Laurent Bugnion, .

MultiTouch Windows Phone 7

+1
source

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


All Articles