How to get Path Data from Path

BitSmithy 1,771 Reputation points
2020-01-19T21:58:57.62+00:00

Hello,

I create Path from XAML:

Next I want to get Path data from the UIElement and show to the user.
How to get Path data from UIElement?

Universal Windows Platform (UWP)
{count} votes

1 answer

Sort by: Most helpful
  1. Fay Wang - MSFT 5,196 Reputation points
    2020-01-20T02:17:04.74+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    For Windows Runtime XAML, the move and draw commands produce a PathGeometry, you can get it by using myPath.Data, the PathGeometry has a single PathFigure object with a Figures property value. Each draw command produces a PathSegment derived class in that single PathFigure's Segments collection, the move command changes the StartPoint, you can get the point value and operation by checking every PathSegment like below. And for more details about Path.Data, you can refer to Move and draw commands syntax.

    PathGeometry pp = myPath.Data as PathGeometry;  
    PathFigureCollection figures = pp.Figures;  
    foreach (var figure in figures)  
    {  
        PathSegmentCollection segs = figure.Segments;  
        foreach (PathSegment seg in segs)  
        {  
            //point or other operation  
        }  
    }      
     
    

    In addition, you can refer to this link to check how to add xaml code.

    0 comments No comments