Drawingvisual use Pen from a Pen property

276 Views Asked by At

My main aim is to update drawingvisuals thicknesses when I zoom on canvas. It takes very long time to update each drawingvisual if there are too much drawing visuals (like 100.000 lines) in the canvas. So I decided to have a Pen property in my class then create the dravingvisuals with that pen. Pen thickness property is in binding with zoom ratio of canvas. This way zooming works whell, it is fast enough and thicknesses of draving visuals are being updated correctly. Problem on that point is creating 100000 lines takes too much time about 4 minutes.

public Pen pen { get; set; }

private void test()
{
    Point lastPoint=new Point(0,0);
    double lastAngle=0;

    for (int i = 1; i <100000; i++)
    {
       Line temp = new Line(lastPoint, lastAngle, 20);          

       _lineList.Add(temp);
       lastPoint = temp.Point2;
       lastAngle = lastAngle > 360 ? 0 : lastAngle + 30;            
    }

    foreach (Line l in _lineList)
    {               
      VisualAdd(l.Geometri(), l.CNID, pen);
    }
}

public void VisualAdd(Geometry g, int id, Pen p)
{
    DrawingVisual c = DrawingVisualCreate(g, id, p);
  _children.Add(DrawingVisualOlustur(g,id,p));
}



private DrawingVisual DrawingVisualCreate(Geometry g, int id,Pen p)
{                             
    DrawingVisual drawingVisual = new DrawingVisual();
    DrawingContext drawingContext = drawingVisual.RenderOpen();
    drawingContext.DrawGeometry(null, p, g);
    drawingContext.Close();
    drawingVisual.Id = id;
    return drawingVisual;
}

If I create the drawing visual like below to create 100000 lines takes only 2 seconds. But as I explain then to update the thickness while zooming is going to be big problem.

public void VisualAdd(Geometry g, int id)
{
    DrawingVisual c = DrawingVisualCreate(g, id);
  _children.Add(DrawingVisualOlustur(g,id,p));
}

private DrawingVisual DrawingVisualCreate(Geometry g, int id)
{                             
    DrawingVisual drawingVisual = new DrawingVisual();
    DrawingContext drawingContext = drawingVisual.RenderOpen();
    drawingContext.DrawGeometry(null, new Pen(Brushes.Black,1), g);
    drawingContext.Close();
    drawingVisual.Id = id;
    return drawingVisual;
}

I dont understand why it is so that slow when creating with a pen which is a created property.

0

There are 0 best solutions below