문제

I have an Image as shown below. Using MatrixTransform I can easily zoom in and out. How can I detect if zooming is too small/large? E.g. I would like to limit zooming to 10-200%.

<ScrollViewer x:Name="scrollViewer" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto">
   <Border x:Name="border" ClipToBounds="True" Width="Auto" Height="Auto">
     <Image x:Name="image" Source="test.png"/>
   </Border>
 </ScrollViewer>

The actual transformation:

Point p = e.MouseDevice.GetPosition(image);

Matrix m = image.RenderTransform.Value;
if (e.Delta > 0)
    m.ScaleAtPrepend(1.1, 1.1, p.X, p.Y);
else
    m.ScaleAtPrepend(1.0 / 1.1, 1.0 / 1.1, p.X, p.Y);

// How do I know if the zoom level is lower than 10% or higher than 200%?
image.RenderTransform = new MatrixTransform(m);
도움이 되었습니까?

해결책

Unless you also rotate, Matrix.M11 (or M22) gives you the scaling factor.

Matrix m = image.RenderTransform.Value;
...
if (m.M11 >= 0.1 && m.M11 <= 2.0)
{
    image.RenderTransform = new MatrixTransform(m);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top