C#帆布涂得太多了
在我的C#帆布涂得太多了,c#,wpf,user-interface,line,draw,C#,Wpf,User Interface,Line,Draw,在我的main窗口中有一个Canvas,我在那里画了一条线。当它在我的画布的宽度/高度上绘制时,绘图将继续在我的主窗口中进行。我的代码中有错误还是正常 <Canvas x:Name="coordinateSystem" HorizontalAlignment="Right" Height="580" Margin="0,10,283,0" VerticalAlignment="Top" Width="1024" Cursor="Cross" UseLayoutRounding="False
main窗口中有一个Canvas
,我在那里画了一条线。当它在我的画布的宽度/高度上绘制时,绘图将继续在我的主窗口中进行。我的代码中有错误还是正常
<Canvas x:Name="coordinateSystem" HorizontalAlignment="Right" Height="580" Margin="0,10,283,0" VerticalAlignment="Top" Width="1024" Cursor="Cross" UseLayoutRounding="False"/>
thx
PS:
有办法保存所有绘制的点吗?我希望以后调整画布的大小(缩小/放大),或者如果时间太长,请在画布中移动绘制的线条,然后我需要再次绘制所有点。画布不剪裁子元素。如果要停止在画布外部绘制子元素,则需要将ClipToBounds设置为true或设置画布的剪辑
// 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;
}