Search code examples
c#xamlshapesdrawing2dwinrt-component

Convert Ellipse or EllipseGeometry to PathFigure on Windows Phone 8.1


I've stumbled upon converting Ellipse to PathGeometry. I've tried to use ArcSegment to present Ellipse, but still don't know how to convert Ellipse size to ArcSegment size. I'm trying to segment Ellipse into two part, but there are other approaches, i.e. Bezier curves. Need clues how to convert Ellipse to ArcSegment collection. The whole process could be looking like that:

public static PathFigure ToFigures(this Ellipse ellipse)
{
    var pathFigure = new PathFigure {IsClosed = true};
    var arcSegment1 = new ArcSegment();
    var arcSegment2 = new ArcSegment();
    pathFigure.Segments.Add(arcSegment1);
    pathFigure.Segments.Add(arcSegment2);
    return pathFigure;
}

Solution

  • You could directly use an EllipseGeometry for the Path Data:

    path = new Path
    {
        Data = new EllipseGeometry { RadiusX = 100, RadiusY = 50 }
    };
    

    Using the size of the Ellipse it would look like this:

    path = new Path
    {
        Data = new EllipseGeometry
        {
            RadiusX = ellipse.ActualWidth / 2,
            RadiusY = ellipse.ActualHeight / 2
        }
    };