title: Changing the Zoom In/Out centerpoint
body: <p>I'm writing a WPF application that displays a XAML object (it's basically a map drawn in XAML). As part of its features, it should zoom in/out and pan. The panning works fine, and the zoom zooms, but I can't quite understand how to zoom to a specific point, like my mouse cursor, for example.</p>
  
  <p>This is my current code:</p>
  
  <pre><code>internal void PerformZoom(float ZoomFactor, Point ZoomCenterPoint)
  {
    m_originalTransform = m_canvas.RenderTransform;
    float newZoomFactor = m_oldZoomFactor + ZoomFactor;
  
    float scaleToApply = (newZoomFactor / m_oldZoomFactor);
    m_totalZoom = newZoomFactor;
  
    var st = new ScaleTransform(scaleToApply, scaleToApply);
  
    TransformGroup tg = new TransformGroup();
    tg.Children.Add(m_originalTransform);
    tg.Children.Add(st);
    m_canvas.RenderTransform = tg;
  
    m_oldZoomFactor = newZoomFactor;
  }
  </code></pre>
  
  <p><strong>[edit]</strong> Found the solution - Just edited the CenterX / CenterY properties of the transformation and it worked like a charm.
  Thanks for all your help!</p>
  
  <p><strong>[edit2]</strong> Here's a viable solution (considering the mouse position):</p>
  
  <pre><code>public partial class MainWindow
  {
      private float currentZoom = 1f;
      private const float StepSize = .2f;
  
      public MainWindow()
      {
          InitializeComponent();
      }
  
      private void MainGrid_OnMouseWheel(object sender, MouseWheelEventArgs e)
      {
          var pos = 1;
          if (e.Delta &lt; 0)
          {
              pos = -1;
          }
  
          var mousePosition = e.MouseDevice.GetPosition(MainGrid);
  
          currentZoom += StepSize * pos;
          var transform = new ScaleTransform(currentZoom, currentZoom, mousePosition.X, mousePosition.Y);
          MainGrid.RenderTransform = transform;
      }
  }
  </code></pre>