WPF缩放-矩阵变换

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_33712555/article/details/83088948

WPF缩放-矩阵变换

<Grid Margin="0 0 0 0" Grid.Column="1" x:Name="CanvasListPnl"
	MouseDown="CanvasListPnl_MouseDown"
	MouseUp="CanvasListPnl_MouseUp"
	MouseWheel="CanvasListPnl_MouseWheel"
	ClipToBounds="True">
	
    <Grid.RenderTransform>
    	<MatrixTransform x:Name="transForm"></MatrixTransform>
    </Grid.RenderTransform>
</Grid>
</Grid>

        private void CanvasListPnl_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            var center = getPosition(sender, e);
            var scale = (e.Delta > 0 ? 1.2 : 1 / 1.2);

            var matrix = transForm.Matrix;
            matrix.ScaleAt(scale, scale, center.X, center.Y);

            (e.OriginalSource as Canvas).Children.Clear();

            transForm.Matrix = matrix;

            DrawXYAxis(28,34);
        }

        Point getPosition(object sender, MouseEventArgs e)
        {
            return e.GetPosition(sender as UIElement) * transForm.Matrix;
        }
展开阅读全文

没有更多推荐了,返回首页