Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need help to convert XAML into C# code

Tags:

wpf

this is a piece of XAML script that draw a Bezier code. What I need is a pure C# code behind that achieve the same result but not using XAML.

Can anybody help convert it into C# code?

Thanks in advance!

Mike

<Path Stroke="Black" StrokeThickness="1">
  <Path.Data>
    <PathGeometry>
      <PathGeometry.Figures>
        <PathFigureCollection>
          <PathFigure StartPoint="10,100">
            <PathFigure.Segments>
              <PathSegmentCollection>
                <BezierSegment Point1="100,0" Point2="200,200" Point3="300,100" />
              </PathSegmentCollection>
            </PathFigure.Segments>
          </PathFigure>
        </PathFigureCollection>
      </PathGeometry.Figures>
    </PathGeometry>
  </Path.Data>
</Path>

1 Answers

I tested this code and it works.

        Path path = new Path();
        path.Stroke = new SolidColorBrush(Colors.Black);
        path.StrokeThickness = 10;
        PathGeometry pg = new PathGeometry();
        PathFigureCollection pfc = new PathFigureCollection();
        PathFigure fig = new PathFigure();
        PathSegmentCollection psc = new PathSegmentCollection();
        BezierSegment bs1 = new BezierSegment(new Point(100, 0), new Point(200, 200), new Point(300, 100), true);
        psc.Add(bs1);
        fig.Segments = psc;
        pfc.Add(fig);
        pg.Figures = pfc;
        path.Data = pg;
like image 154
John Avatar answered Jun 08 '26 12:06

John



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!