这是一段绘制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>
答案 0 :(得分:4)
我测试了这段代码并且有效。
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;
答案 1 :(得分:0)
Path path = new Path();
path.Stroke = Brushes.Black;
path.StrokeThickness = 1;
PathGeometry pg = new PathGeometry();
PathFigureCollection pfc = new PathFigureCollection();
PathFigure fig = new PathFigure();
fig.StartPoint = new Point(10,100);
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;
canvas.Children.Add(path);