title: Apply offset to scaling to preserve a specific point
body: <p>I am currently struggling with a WPF canvas and scaling. I want to be able to scale the canvas around a specific point (the given point should stay at the same screen position after scaling).  </p>
  
  <p>The scaling is done with a simple <strong>ScaleTransform</strong>. The Translation is stored in a <strong>Point</strong> object and is applied to all shapes in the canvas. That means that I have to offset all shapes (modify the Translation Point) after the scaling was applied. For the sake of simplicity, here a simplified code</p>
  
  <pre><code>class CanvasManager
  {
      Point mTranslation; // holds the translation
      Canvas mCanvas;
      ScaleTransform mCanvasScale; // linked to mCanvas
  
      // Constructor omitted
  
      public void Scale(double factor, Point pt)
      {
          // retrieve the previous scaling factor
          double oldfactor = mCanvasScale.ScaleX;
          //apply the new factor
          mCanvasScale.ScaleX = factor;
          mCanvasScale.ScaleY = factor;
          // now offset so Point pt gets back at its original position
          mTranslation.X += ???;
          mTranslation.Y += ???;
      }
  }
  </code></pre>
  
  <p>Point <strong>pt</strong> is coming from the mouse event measured relative to the canvas and includes the scaling. (When the Scale is 2 then a relative screen x-coordinate of 200 gives me 400 as the value for <strong>pt</strong>)<br>
  The Transform (Scale) is applied with the following code snippet:</p>
  
  <pre><code>mCanvasScale = new ScaleTransform();
  mCanvas.LayoutTransform = mCanvasScale;
  </code></pre>
  
  <p>How do I get my correct offset for mTranslation?  </p>
  
  <p>Best regards<br>
  Dennis</p>