question

BitSmithy-4663 avatar image
0 Votes"
BitSmithy-4663 asked ·

How to get Path Data from Path

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?

windows-uwp
· 2
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

 XAML below:


0 Votes 0 · ·

XAML below:

     <Path x:Name="myPath" Stroke="DarkGoldenRod" StrokeThickness="3" Margin="0,30,0,0"
             Data="M 10,50 h 100 a 20,20 180 0 1 150,0 h 100 v 80 h-100 a 20,20 180 0 1 -150,0 h-100  z" >
         </Path >
0 Votes 0 · ·

1 Answer

FayWang-MSFT avatar image
0 Votes"
FayWang-MSFT answered ·

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.


· Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.