WPF缩放-矩阵变换
原创
©著作权归作者所有:来自51CTO博客作者wx5aab5af48c1c4的原创作品,请联系作者获取转载授权,否则将追究法律责任
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;
}