캔버스를 확대하거나 축소해야합니다. 그러나 확대/축소는 항상 캔버스가 아닌 화면의 중앙에 위치해야합니다. 그리고 이것은 현재 코드에서 작동하지 않습니다! 항상 캔버스의 중심으로 확대되며 현재 화면은 확대되지 않습니다. 캔버스도 움직일 수 있어야하지만 테두리에서 멀리 떨어지도록 움직여서는 안됩니다.캔버스의 뷰포트 중심으로 확대 및 축소
XAML
<Grid>
<Canvas HorizontalAlignment="Left" Name="canvas1" VerticalAlignment="Top">
</Canvas>
</Grid>
를 C#
// x & y arent the position, it's how many pixel the object should move to the left/right etc
public void setPosition(double x, double y)
{
Thickness t = new Thickness(canvas1.Margin.Left + x, canvas1.Margin.Top + y, 0, 0);
if (t.Left > 0)
{
t.Left = 0;
}
else if(t.Left < -(canvas1.Width - System.Windows.SystemParameters.PrimaryScreenWidth))
{
t.Left = -(canvas1.Width - System.Windows.SystemParameters.PrimaryScreenWidth);
}
if (t.Top > 0)
{
t.Top = 0;
}
else if (t.Top < -(canvas1.Height - System.Windows.SystemParameters.PrimaryScreenHeight))
{
t.Top = -(canvas1.Height - System.Windows.SystemParameters.PrimaryScreenHeight);
}
canvas1.Margin = t;
}
public void setZoom(double zoom)
{
double tempW = canvas1.Width;
double tempH = canvas1.Height;
canvas1.Width *= (1 + zoom);
canvas1.Height *= (1 + zoom);
Debug.WriteLine("tempW: " + tempW + " tempH: " + tempH + " canvas1.Width: " + canvas1.Width + " canvas1.Height: " + canvas1.Height);
setPosition((tempW - canvas1.Width)/2, ((tempH - canvas1.Height)/2));
}
그리고 그래 내가 거기에 물건을 ScaleTransform 비슷하지만 몇 가지 이유로이 더 성능이 좋은 것을 알고 .. 물어 해달라고 : 이것은 내가 지금까지 무엇을 가지고 나 왜!
누군가 나를 도와 줄 수 있습니까?
이것이 더 높은 성능을 갖는 이유는 실제로 확대/축소하지 않기 때문입니다. 당신이 틀린 캔버스의 크기는 다른 캔버스의 크기에 영향을 미치지 않기 때문에 캔버스의 크기를 변경합니다. –
저는이 Grid + Canvas가 ViewBox 안에 있다고 가정합니다. 해당 뷰 박스 자체가 ScaleTransform을 사용하고 있습니다. 뷰 박스를 건너 뛰고 ScaleTransform을 직접 사용하려고 할 수 있습니다. –