As I said, you only need one visual and inside, you can have all your lines.
Take a look at this:
First, we define several drawings within our drawing context:
class EllipseAndRectangle : DrawingVisual
{
public EllipseAndRectangle()
{
using (DrawingContext dc = RenderOpen())
{
dc.DrawEllipse(Brushes.Black,
new Pen(Brushes.Blue, 3),
new Point(120, 120), 20, 40);
dc.DrawRectangle(Brushes.Red,
new Pen(Brushes.Green, 4),
new Rect(new Point(10, 10), new Point(80, 80)));
}
}
}
This is what one visual visual or element places all the drawings:
public class EllAndRectHost : FrameworkElement
{
private EllipseAndRectangle _ellAndRect = new EllipseAndRectangle();
protected override Visual GetVisualChild(int index)
{
return _ellAndRect;
}
protected override int VisualChildrenCount
{
get
{
return 1;
}
}
}
XAML:
<local:EllAndRectHost Margin="30" ... />
DrawingVisual, , , 100 100 .
, . , , , , . DrawLine - . , DrawLine. DrawGeometry DrawLine .