0
我在我的MainWindow
中有一个Canvas
,我在那里画了一条线。当它绘制我的Canvas
的宽度/高度时,绘图将继续到我的MainWindow
。我的代码中是否有错误,或者是正常的?C#画布将被覆盖
<Canvas x:Name="coordinateSystem" HorizontalAlignment="Right" Height="580" Margin="0,10,283,0" VerticalAlignment="Top" Width="1024" Cursor="Cross" UseLayoutRounding="False"/>
这里是我的功能,我称之为每次当我得到我行新的坐标:
// xOld, yOld and t are static
// t represents the time
private void drawPoly(double value)
{
t++;
Point pOne = new Point(xOld, yOld);
Point pTwo = new Point(t, value);
GeometryGroup lineGroup = new GeometryGroup();
LineGeometry connectorGeometry = new LineGeometry();
connectorGeometry.StartPoint = pOne;
connectorGeometry.EndPoint = pTwo;
lineGroup.Children.Add(connectorGeometry);
System.Windows.Shapes.Path path = new System.Windows.Shapes.Path();
path.Data = lineGroup;
path.StrokeThickness = 1;
path.Stroke = path.Fill = Brushes.Red;
coordinateSystem.Children.Add(path);
xOld = t;
yOld = value;
}
THX
PS:
有没有办法来保存所有的绘制点?我想稍后调整我的画布大小(缩小/放大),或者如果时间将大幅移动画布中的画线,然后我需要再次绘制所有点。