S
Sebastian Daser
Hi all,
I am trying to develop a WPF application which should show a Polygon Shape
inside an Image control. At a later point the Points of the Polygon should be
calculated by the application, so I need to create the objects in code.
I have tried the following:
public partial class ImageControl : Image
{
public ImageControl()
{
InitializeComponent();
DrawingGroup group = new DrawingGroup();
Polygon polygon = new Polygon();
polygon.Stretch = Stretch.Fill;
polygon.Fill = Brushes.LightGreen;
polygon.Stroke = Brushes.Black;
polygon.Points.Add(new Point(0, 0));
polygon.Points.Add(new Point(0, 0.5));
polygon.Points.Add(new Point(0.7, 0.7));
polygon.Points.Add(new Point(0.5, 0));
Geometry polygonGeometry = polygon.RenderedGeometry;
group.Children.Add(new GeometryDrawing(Brushes.Blue, null,
polygonGeometry));
DrawingImage image = new DrawingImage(group);
this.Source = image;
}
}
However this does not work. When replacing the line
Geometry polygonGeometry = polygon.RenderedGeometry;
with something like
Geometry polygonGeometry = Geometry.Parse("M100,125 L300, 330 L700, 260
L430, 10");
a Polygon is drawn, so I guess the RenderGeometry method does not produce
the desired result.
How can I convert a Shape like Polygon to an object of type Geometry or
GeometryDrawing?
Thanks and kind regards
Sebastian
I am trying to develop a WPF application which should show a Polygon Shape
inside an Image control. At a later point the Points of the Polygon should be
calculated by the application, so I need to create the objects in code.
I have tried the following:
public partial class ImageControl : Image
{
public ImageControl()
{
InitializeComponent();
DrawingGroup group = new DrawingGroup();
Polygon polygon = new Polygon();
polygon.Stretch = Stretch.Fill;
polygon.Fill = Brushes.LightGreen;
polygon.Stroke = Brushes.Black;
polygon.Points.Add(new Point(0, 0));
polygon.Points.Add(new Point(0, 0.5));
polygon.Points.Add(new Point(0.7, 0.7));
polygon.Points.Add(new Point(0.5, 0));
Geometry polygonGeometry = polygon.RenderedGeometry;
group.Children.Add(new GeometryDrawing(Brushes.Blue, null,
polygonGeometry));
DrawingImage image = new DrawingImage(group);
this.Source = image;
}
}
However this does not work. When replacing the line
Geometry polygonGeometry = polygon.RenderedGeometry;
with something like
Geometry polygonGeometry = Geometry.Parse("M100,125 L300, 330 L700, 260
L430, 10");
a Polygon is drawn, so I guess the RenderGeometry method does not produce
the desired result.
How can I convert a Shape like Polygon to an object of type Geometry or
GeometryDrawing?
Thanks and kind regards
Sebastian