I would like to zoom an image in WPF and that the image visual render be inside a constrained sized item control.
For example:
<Canvas x:Name="m_canvas" MaxWidth="300" MaxHeight="300" >
<Image Source="..."
Width="300"
Height="300" />
</Canvas>
The zoom code:
var matrix = ((MatrixTransform)m_imag开发者_如何转开发e.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;
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.
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
You could clip to the bounds of the Canvas
:
<Canvas ClipToBounds="True" ...>
But I don't understand why you're using a Canvas
in the first place. It's likely that there's a much nicer way to approach your particular problem without the need for hard-coded widths and heights and without any Canvas
at all.
精彩评论