gpt4 book ai didi

wpf - 需要帮助将 XAML 转换为 C# 代码

转载 作者:行者123 更新时间:2023-12-04 15:42:51 25 4
gpt4 key购买 nike

这是一段绘制贝塞尔曲线的 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;

关于wpf - 需要帮助将 XAML 转换为 C# 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1335433/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com