WPF:隐藏绘制的点

时间:2013-06-20 11:31:54

标签: c# wpf drawing

我的班级Drawing中有一个名为drawPoly(...)的函数,此函数绘制点并连接它们。我想要的是,如何将它们隐藏在画布中?我有8个班级绘图实例。如果可能的话,我不想删除整个Canvas,只需隐藏绘制的点。

private double t = 0;     // x Startpostion für Graph
private double xOld = 0;  // x Startpostion für Graph
private double yOld = 100;

System.Windows.Shapes.Path path;    

public GeometryGroup pointGroupDrawing = new GeometryGroup();

...

public void drawPoly(double value, Brush colorBrush, int thickness)
{
    // is for the x-Axis /time
    t++;

    // get old value and generate new point 
    Point pOne = new Point(xOld, yOld);
    Point pTwo = new Point(t, value);

    // connect old point wit new point
    GeometryGroup lineGroup = new GeometryGroup();

    LineGeometry connectorGeometry = new LineGeometry();
    connectorGeometry.StartPoint = pOne;
    connectorGeometry.EndPoint = pTwo;
    lineGroup.Children.Add(connectorGeometry);
    path = new System.Windows.Shapes.Path();
    path.Data = lineGroup;
    path.StrokeThickness = thickness;
    path.Stroke = path.Fill = colorBrush;

    // collect point for redrawing later ?
    pointGroupDrawing.Children.Add(connectorGeometry);

    // replace old point with new
    xOld = t;
    yOld = value;

    coordinateSystem.Children.Add(path);        
}

我可以使用此pointGroupDrawing.Children.Add(connectorGeometry);隐藏旧点吗?

2 个答案:

答案 0 :(得分:1)

System.Windows.Shapes.Path具有Visibility属性。将其设置为Hidden

path.Visibility = Visibility.Hidden;

答案 1 :(得分:0)

我不明白你的问题。这些点本身不应该是可见的。只是路径有一个visiblity属性。

您可以设置路径的visibility属性以将其隐藏在画布中。如果要对画布中的所有路径执行此操作,可以迭代它的子项并将可见性设置为visibility.hidden