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:
有沒有辦法來保存所有的繪製點?我想稍後調整我的畫布大小(縮小/放大),或者如果時間將大幅移動畫布中的畫線,然後我需要再次繪製所有點。