protected override void OnManipulationDelta(ManipulationDeltaEventArgs args) { try { UIElement element = args.Source as UIElement; MatrixTransform xform = element.RenderTransform as MatrixTransform; Matrix matrix = xform.Matrix; ManipulationDelta delta = args.DeltaManipulation; Point center = args.ManipulationOrigin; /* * matrix.Translate(-center.X, -center.Y); * matrix.Scale(delta.Scale.X, delta.Scale.Y); * matrix.Rotate(delta.Rotation); * matrix.Translate(center.X, center.Y); * matrix.Translate(delta.Translation.X, delta.Translation.Y); * xform.Matrix = matrix; */ Matrix to = matrix; to.Translate(-center.X, -center.Y); to.Scale(delta.Scale.X, delta.Scale.Y); to.Rotate(delta.Rotation); to.Translate(center.X, center.Y); to.Translate(delta.Translation.X, delta.Translation.Y); MatrixAnimation b = new MatrixAnimation() { From = matrix, To = to, Duration = TimeSpan.FromMilliseconds(0), FillBehavior = FillBehavior.HoldEnd }; (element.RenderTransform as MatrixTransform).BeginAnimation(MatrixTransform.MatrixProperty, b); //tbTranslate.Text = string.Format("Translation: {0}, {1}", delta.Translation.X, delta.Translation.Y); //tbTranslate.Text += string.Format("\r\nTotal Translation: {0}, {1}", args.CumulativeManipulation.Translation.X, args.CumulativeManipulation.Translation.Y); args.Handled = true; base.OnManipulationDelta(args); } catch { //MessageBox.Show("OnManipulationDelta"); }; }
protected override void OnManipulationCompleted(ManipulationCompletedEventArgs e) { try { // tbCompleted.Text = string.Format("{0}", e.FinalVelocities.LinearVelocity); // tbCompleted.Text += string.Format("\r\n{0}", e.TotalManipulation.Translation); UIElement el = e.Source as UIElement; //el.Effect = new BlurEffect() { Radius = 10.0 }; MatrixTransform xform = el.RenderTransform as MatrixTransform; Matrix matrix = xform.Matrix; Matrix from = matrix; Matrix to = matrix; to.Translate( e.TotalManipulation.Translation.X * Math.Abs(e.FinalVelocities.LinearVelocity.X), e.TotalManipulation.Translation.Y * Math.Abs(e.FinalVelocities.LinearVelocity.Y)); if (Math.Abs(e.FinalVelocities.LinearVelocity.X) > 0.5 || Math.Abs(e.FinalVelocities.LinearVelocity.Y) > 0.5) { MatrixAnimation b = new MatrixAnimation() { From = from, To = to, Duration = TimeSpan.FromMilliseconds(500), FillBehavior = FillBehavior.HoldEnd }; b.Completed += new EventHandler(b_Completed); (el.RenderTransform as MatrixTransform).BeginAnimation(MatrixTransform.MatrixProperty, b); } base.OnManipulationCompleted(e); //label1.Content = "to : " + to.OffsetY.ToString() + "\nel : " + xform.Matrix.OffsetY.ToString() + "\ne.total : " + e.TotalManipulation.Translation.Y.ToString() + "\ne.final : " + e.FinalVelocities.LinearVelocity.Y.ToString(); currImgDestination = to; currImgVelocity = e.FinalVelocities.LinearVelocity; currManipulImage = el as Image; } catch { //MessageBox.Show("OnManipulationCompleted"); }; }