Guest User

Untitled

a guest
Aug 14th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. Manipulation event on canvas
  2. private void Canvas1_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
  3. {
  4. Canvas CSender = (Canvas)sender;
  5. ScaleTransform scale = (ScaleTransform)CSender.RenderTransform;
  6.  
  7. if ((e.DeltaManipulation.Translation.X != 0 || e.DeltaManipulation.Translation.Y != 0) && (scale.ScaleX != 1 || scale.ScaleY != 1))
  8. {
  9.  
  10. scale.CenterX -= e.DeltaManipulation.Translation.X;
  11. scale.CenterY -= e.DeltaManipulation.Translation.Y;
  12.  
  13. }
  14. else if (e.DeltaManipulation.Scale.X != 0 || e.DeltaManipulation.Scale.Y != 0)
  15. {
  16. double factor = (e.DeltaManipulation.Scale.X >= e.DeltaManipulation.Scale.Y) ? e.DeltaManipulation.Scale.X : e.DeltaManipulation.Scale.Y;
  17.  
  18. if (e.CumulativeManipulation.Scale.X == 1 && e.CumulativeManipulation.Scale.Y == 1)
  19. {
  20. scale.CenterX -= e.DeltaManipulation.Translation.X;
  21. scale.CenterY -= e.DeltaManipulation.Translation.Y;
  22.  
  23. }
  24. if (scale.ScaleX * factor <= MIN_ZOOM || scale.ScaleY * factor <= MIN_ZOOM)
  25. {
  26. scale.ScaleX = MIN_ZOOM;
  27. scale.ScaleY = MIN_ZOOM;
  28. foreach (Rectangles R in RectanglesList)
  29. {
  30. R.X = R.X* scale.ScaleX;
  31. R.Y = R.Y* scale.ScaleY;
  32. }
  33.  
  34. }
  35.  
  36. else if (scale.ScaleX * factor >= MAX_ZOOM || scale.ScaleY * factor >= MAX_ZOOM)
  37. {
  38. scale.ScaleX = MAX_ZOOM;
  39. scale.ScaleY = MAX_ZOOM;
  40.  
  41. foreach (Rectangles R in RectanglesList)
  42. {
  43. R.X = R.X * scale.ScaleX;
  44. R.Y = R.Y * scale.ScaleY;
  45. }
  46. }
  47. else
  48. {
  49. scale.ScaleX *= factor;
  50. scale.ScaleY *= factor;
  51. foreach (Rectangles R in RectanglesList)
  52. {
  53. R.X = R.X * scale.ScaleX;
  54. R.Y = R.Y * scale.ScaleY;
  55. }
  56. }
  57. }
Add Comment
Please, Sign In to add comment