【问题标题】:WPF: Hide drawn pointsWPF:隐藏绘制的点
【发布时间】:2013-06-20 11:31:54
【问题描述】:

我的班级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); 隐藏旧点吗?

【问题讨论】:

  • 为什么要隐藏点?

标签: c# wpf drawing


【解决方案1】:

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

path.Visibility = Visibility.Hidden;

【讨论】:

  • 我也可以隐藏旧点吗? public GeometryGroup pointGroupDrawing = new GeometryGroup(); pointGroupDrawing.Children.Add(connectorGeometry);
  • 不确定你的意思。您是否可能不断地向折线添加点,并且想要删除旧点并仅保留最后一个 n
  • 是的,这就是我的意思,我在 pointGroupDrawing 中收集了所有旧点,但是如何在画布上隐藏这些点?
  • 那么您最好使用Polyline 而不是Path 并在每次更新时设置其Points 属性。
【解决方案2】:

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

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

【讨论】:

  • 我在 pointGroupDrawing 中收集了所有旧点,但是如何在画布上隐藏这些点?
  • 我认为你应该使用 Polyline 而不是 Path
猜你喜欢
  • 1970-01-01
  • 2021-07-30
  • 1970-01-01
  • 1970-01-01
  • 2021-01-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-21
相关资源
最近更新 更多