title: WPF - Zoom image (inside an constrained sized item control)
body: <p>I would like to zoom an image in WPF and that the image visual render be inside a constrained sized item control.</p>
  
  <p>For example:</p>
  
  <pre><code>&lt;Canvas x:Name="m_canvas" MaxWidth="300" MaxHeight="300" &gt;
     &lt;Image Source="..."
        Width="300"
        Height="300" /&gt;
  &lt;/Canvas&gt;
  </code></pre>
  
  <p>The zoom code:</p>
  
  <pre><code>var matrix = ((MatrixTransform)m_image.RenderTransform).Matrix;
  
  var center = new Point(m_image.ActualWidth / 2, m_image.ActualHeight / 2);
  center = matrix.Transform(center);
  
  matrix.ScaleAt(delta.Scale.X, delta.Scale.Y, center.X, center.Y);
  
  ((MatrixTransform)m_image.RenderTransform).Matrix = matrix;
  </code></pre>
  
  <p>The problem is that when I'm zooming the image render size go larger that the canvas limit (300x300). I would like if the image can zoom only in the canvas.</p>
  
  <p>I don't want to limit the max zoom, I want that if the render size of the image is larger that the canvas, it's stay inside. I don't want that it overlap the canvas</p>