Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In your example you have a number of <code>LineGeometry</code> instances inside a <code>GeometryGroup</code> inside a <code>GeometryDrawing</code>.</p> <p>First, I'd link to bring to your attention that you're not actually using the <code>GeometryDrawing</code>. In your example you've used it solely as a place holder for your <code>GemetryGroup</code>.</p> <p>Ignoring this the problem is that <code>LineGeometry</code> instances were not intended to draw shapes and <code>GeometryGroup</code> is not able to realize that your 6 <code>LineSegments</code> together form a closed shape.</p> <p>Despair not however as there is a way to accomplish what you want: <code>PathGeometry</code>. This geometry essentially defines the contour of a region that may be filled! This contour may is defined by a starting point and a series of <code>PathSegment</code>s.</p> <pre><code>private Point GetExtremity(Point center, double radius, double orientation) { return new Point( center.X + Math.Cos(orientation) * radius, center.Y + Math.Sin(orientation) * radius ); } public void DrawUniformShape(DrawingContext context, Brush brush, Pen pen, Point center, double radius, int sides, double orientationRadians) { context.DrawGeometry( brush, pen, new PathGeometry( Enumerable.Repeat( new PathFigure( GetExtremity(center, radius, orientationRadians), from vertex in Enumerable.Range(1, sides - 1) let angle = orientationRadians + vertex * 2 * Math.PI / sides select new LineSegment(GetExtremity(center, radius, angle), true), true ), 1 ) ) ); } public void DrawBarnColouredHexagon(DrawingContext context, Point center, double radius, double orientation) { DrawUniformShape( context, Brushes.Red, new Pen(Brushes.White, 2), center, radius, 6, 0 ); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload