Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#帆布涂得太多了_C#_Wpf_User Interface_Line_Draw - Fatal编程技术网

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;
}