Hello,
found the following links but its not applicable for .net maui?
Yes, this link used Geomerty from System.Windows.Media namespace. But you used Geomerty from Microsoft.Maui.Controls.Shapes
they are different.
I cannot find Api to convert Geometry to the string directly, if you need it, we can convert it by ourselves.
Firstly, we cannot get point data from the Geometry
, ConvertFromInvariantString
retrun the PathGeometry
, we can use it to get the startPoint, for the start point, we need add "M" at the begin
and add L in the end of the start point.
To get following points, we need to get PathSegmentCollection
by pathFigure.Segments
, and traverse the PathSegmentCollection to get all the remaining points, by the way, do not add Z at the end of the string.
string OrString = "M13.908992,16.207977 L32.000049,16.207977 32.000049,31.999985 13.908992,30.109983Z";
PathGeometry pathData = (PathGeometry)new PathGeometryConverter().ConvertFromInvariantString(OrString);
PathFigure pathFigure= pathData.Figures.FirstOrDefault();
StringBuilder GeometryToString = new StringBuilder();
Point startPoint= pathFigure.StartPoint;
GeometryToString.Append("M"+startPoint.X+","+ startPoint.Y+" L");
PathSegmentCollection segments= pathFigure.Segments;
for (int i = 0; i < segments.Count; i++)
{
LineSegment lineSegment= segments[i] as LineSegment;
if (i.Equals(segments.Count - 1))
{
GeometryToString.Append(lineSegment.Point.X + "," + lineSegment.Point.Y + "Z");
}
else
{
GeometryToString.Append(lineSegment.Point.X + "," + lineSegment.Point.Y + " ");
}
}
var endGeometryString = GeometryToString.ToString();
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.