我有一个 150 高 500 宽的画布。在这个画布中,我想添加一些点来生成一条线。生成这条线不是问题。但我想生成一条在连接点之间弯曲的线以获得平滑的曲线。此外,线下方的区域必须填充如下示例所示的颜色。

要循环点,我使用以下简单代码:
Polyline line = new Polyline();
PointCollection collection = new PointCollection();
foreach (Point p in points)
{
collection.Add(p);
}
line.Points = collection;
line.Stroke = new SolidColorBrush(Colors.Black);
line.StrokeThickness = 3;
canv.Children.Add(line);
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
你可以使用一个
多贝塞尔线段
例如这样做
<Canvas>
<Path Stroke="#FF56C0E9" StrokeThickness="10" Fill="#FFC0E5FC" >
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigureCollection>
<PathFigure StartPoint="100,80" IsFilled="True">
<PathFigure.Segments>
<PathSegmentCollection>
<PolyBezierSegment Points="30 300,550 30,10 330" />
</PathSegmentCollection>
</PathFigure.Segments>
</PathFigure>
</PathFigureCollection>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>
</Canvas>
Run Code Online (Sandbox Code Playgroud)
上面的代码生成了这样的曲线
您必须将 PathFigure 的 IsFilled 属性设置为 True
相同的可以从代码后面完成以获取更多详细信息检查here