#752 – Tracking Total Scale when Scaling by Touch Manipulation

When you use touch manipulation events to scale an element, you typically read the Scale property of the ManipulationDelta object passed in to the ManipulationDelta event handler.   This property reports a delta scaling value to apply to the element, derived from the user’s touch manipulation (e.g. pinch/expand).

For example, a scale value of 1.05 says “scale the object 5% larger than it was the last time that this event was fired”.

In the code example below, we also track total scale, relative to the original size of the element.  (Note that we don’t actually scale the element here).

        private Vector totalScale = new Vector(1.0, 1.0);

        private void Image_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            ManipulationDelta md = e.DeltaManipulation;
            Vector scale = md.Scale;

            totalScale.X *= scale.X;
            totalScale.Y *= scale.Y;

            Console.WriteLine(string.Format(
                "Scale: X={0}, Y={1}, TotalScale: X={2}, Y={3}",
                scale.X, scale.Y, totalScale.X, totalScale.Y));

            e.Handled = true;
        }

752-001

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

2 Responses to #752 – Tracking Total Scale when Scaling by Touch Manipulation

  1. Pingback: Dew Drop – February 8, 2013 (#1,496) | Alvin Ashcraft's Morning Dew

  2. Ralph Roza says:

    I love this blog, however, for this item #752, there is an image blocking the view of a portion of the displayed solution.

    I would like to see the full code, please.
    Thanks!

Leave a comment