0
如何使用幾何和ScaleTransform實現縮放到Silverlight中的特定點?你能提出一些算法,以便我可以做到這一點?我的邏輯錯了。我想通過設置縮放的中心點我遇到了一些麻煩。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;
}
由於
我有一個包含在畫布中的xaml文件中的矩形。 <路徑x:名稱=「PathDraw」Stroke =「Brown」StrokeThickness =「1」頁邊距=「200,200,0,0」 > –
如果(將scaleX = 1!){的scaleX =增量> = 0? scaleX * zoomCoeff :(scaleX <= 1?1:scaleX/zoomCoeff); scaleY = delta> = 0? scaleY * zoomCoeff :(scaleY <= 1?1:scaleY/zoomCoeff); } 否則 { 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; –
但這個作品不正確 –