WPF: How to draw this polygon?

I want to draw the following red polygon: enter image description here

The problem is that I use somethign as follows:

Polygon poly = new Polygon();
poly.StrokeThickness = 2;
poly.Stroke = Brushes.Black;
PointCollection points = new PointCollection();

for (int i = 0; i < this.NumberOfMetrics; i++)
{
   points.Add(new Point(MAX_VALUE - this.Metrics[n, i] * Math.Cos(DegreeToRadian(i * (360 / (this.NumberOfMetrics)))), MAX_Y_GUI - this.Metrics[n, i] * Math.Sin(DegreeToRadian(i * (360 / (this.NumberOfMetrics))))));
}       
poly.Points = points;

Then the polygon is always β€œfilled”, and in the example above, red and green polygons are drawn.

I already tried to add 4 "internal" points to the PointCollection, but then nothing is drawn. So how can I achieve this?

I tried the solution suggested by David:

for (int n = 0; n < this.NumberOfRevisions; n++)
            {
                Path path = new Path();

                CombinedGeometry geometry = new CombinedGeometry();
                geometry.GeometryCombineMode = GeometryCombineMode.Union;

                Polygon poly = new Polygon();
                PointCollection points = new PointCollection();

                for (int i = 0; i < this.NumberOfMetrics; i++)
                {
                    points.Add(new Point(MAX_VALUE - this.Metrics[n, i] * Math.Cos(DegreeToRadian(i * (360 / (this.NumberOfMetrics)))), MAX_Y_GUI - this.Metrics[n, i] * Math.Sin(DegreeToRadian(i * (360 / (this.NumberOfMetrics))))));
                }

                poly.Points = points;

                geometry.Geometry1 = poly.RenderedGeometry;


                geometry.Geometry2 = poly.RenderedGeometry;


                path.Data = geometry;

                polygons.Add(poly);

                paths.Add(path);
            }

This is just a test, but I should therefore get the same result as before, but nothing draws. Is there something wrong with my code?

+5
source share
1 answer

, , , , - :

http://msdn.microsoft.com/en-en/library/ms653071%28v=VS.85%29.aspx

, , ( ) , .

, :

  • , PLAIN
  • , PLAIN
  • β†’

Xaml, #, .

: :

Path myPath = new Path();
CombinedGeometry myCombinedGeometry = new CombinedGeometry()

// here you set the combinedGeometry geometries to create the shape you want

myPath.Data = myCombinedGeometry;

myGrid.Children.Add(myPath);

, PATH , Fill/Stroke , . (. xaml , #)

Edit2:

Fill :

for (int n = 0; n < this.NumberOfRevisions; n++)
{
    CombinedGeometry geometry = new CombinedGeometry() { GeometryCombineMode = GeometryCombineMode.Union };

    PointCollection points = new PointCollection();

    for (int i = 0; i < this.NumberOfMetrics; i++)
    {
        points.Add(new Point(MAX_VALUE - this.Metrics[n, i] * Math.Cos(DegreeToRadian(i * (360 / (this.NumberOfMetrics)))), MAX_Y_GUI - this.Metrics[n, i] * Math.Sin(DegreeToRadian(i * (360 / (this.NumberOfMetrics))))));
    }

    Polygon poly = new Polygon();
    poly.Points = points;

    geometry.Geometry1 = poly.RenderedGeometry;
    geometry.Geometry2 = poly.RenderedGeometry;

    polygons.Add(poly);

    paths.Add(path = new Path() { Data = geometry, Fill = Brushes.Red, Stroke = Brushes.Transparent });
}
+5

All Articles