#752 – Tracking Total Scale when Scaling by Touch Manipulation
February 8, 2013 2 Comments
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; }