title: StreamGeometry PolyLineTo performance
body: <p>I have created a custom shape that draws an ObservableCollection'Point using a StreamGeometry. When the signal surpasses the width of the canvas it is drawn on, it wraps around to the begining. Two polyLines are used; one from the beginning of the canvas to the last added point and one from the first added point in the current collection till the end of the canvas:</p>
  
  <pre><code>protected override Geometry DefiningGeometry
      {
          get
          {
              if (this.Points == null || !this.Points.Any())
              {
                  return Geometry.Empty;
              }
  
              var firstGeometryPoints = this.Points.Where(p =&gt; p.Point.X &gt;= this.Points.First().Point.X);
              var secondGeometryPoints = this.Points.Except(firstGeometryPoints);
  
              var geometry = new StreamGeometry();
              using (var context = geometry.Open())
              {
                  context.BeginFigure(firstGeometryPoints.First().Point, true, false);
                  context.PolyLineTo(firstGeometryPoints.Skip(1).Select(x =&gt; x.Point).ToArray(), true, true);
  
                  if (secondGeometryPoints.Any())
                  {
                      context.BeginFigure(secondGeometryPoints.First().Point, true, false);
                      context.PolyLineTo(secondGeometryPoints.Skip(1).Select(x =&gt; x.Point).ToArray(), true, true);
                  }
  
                  geometry.Freeze();
              }
              return geometry;
          }
      }
  </code></pre>
  
  <p>Whenever the Points collection changes I use InvalidateVisual() to force a redraw of the shape. But since data points are added at 500 samples per second, the application starts to lag. Is there another way of creating this type of graph without redrawing the entire shape on every sample?</p>