这是一段绘制Bezier代码的XAML脚本。我需要的是纯C#代码,可以达到相同的结果,但不使用XAML。
有人可以帮助将其转换为C#代码吗?
提前致谢!
麦克风
<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>
最佳答案
我测试了此代码,它可以工作。
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;