Use dc.DrawGeometry
to create filled-in shapes.
Edit: This:
private DrawingVisual CreateTriangle()
{
var triangle = new DrawingVisual();
using (DrawingContext dc = triangle.RenderOpen())
{
var start = new Point(0, 50);
var segments = new []
{
new LineSegment(new Point(50,0), true),
new LineSegment(new Point(50, 100), true)
};
var figure = new PathFigure(start, segments, true);
var geo = new PathGeometry(new [] { figure });
dc.DrawGeometry(Brushes.Red, null, geo);
var drawingPen = new Pen(Brushes.Black, 3);
dc.DrawLine(drawingPen, new Point(0, 50), new Point(50, 0));
dc.DrawLine(drawingPen, new Point(50, 0), new Point(50, 100));
dc.DrawLine(drawingPen, new Point(50, 100), new Point(0, 50));
}
return triangle;
}
On a side note, if you have to create the PathGeometry
anyway and you use DrawGeometry
you might as well stroke it too, then you don't need your original line drawings.
dc.DrawGeometry(Brushes.Red, new Pen(Brushes.Black, 3), geo);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…