如何使用几何和 ScaleTransform 在 Silverlight 中实现缩放到特定点?你能建议一些算法,以便我可以实现这一点吗?我的逻辑是错误的。我认为设置缩放的中心点会遇到一些麻烦。
这是我在 xaml 文件中的几何数据
<Canvas x:Name="LayoutRoot" Background="Orchid" MouseWheel="PathDraw_OnMouseWheel">
<Path x:Name="PathDraw" Stroke="Brown" StrokeThickness="1" Margin="200,200,0,0">
<Path.Data>
<RectangleGeometry x:Name="rect" Rect="80 80 80 80"/>
</Path.Data>
</Path>
</Canvas>
下面是缩放逻辑。
private static int ZoomSteps = 0;
private static double centerX = 0;
private static double centerY = 0;
private double zoomCoeff = 1.1;
private void PathDraw_OnMouseWheel(object sender, MouseWheelEventArgs e)
{
double delta = e.Delta;
if (scaleX != 1)
{
scaleX = delta >= 0 ? scaleX * zoomCoeff : (scaleX <= 1 ? 1 : scaleX / zoomCoeff);
scaleY = delta >= 0 ? scaleY * zoomCoeff : (scaleY <= 1 ? 1 : scaleY/zoomCoeff);
}
else
{
scaleX = scaleY = delta >= 0 ? zoomCoeff : 1;
}
scale = new ScaleTransform { ScaleX = scaleX, ScaleY = scaleY,
CenterX = e.GetPosition(PathDraw).X,
CenterY = e.GetPosition(PathDraw).Y
};
rect.Transform = scale;
}
谢谢