在WPF中填充弧段

时间:2016-05-10 10:20:32

标签: c# wpf

我的场景如下,我在WPF中的两点之间绘制一个弧,我需要填充弧,但我想填充触摸中心的弧扇区,但WPF填充不同。如何以我想要的方式填充圆弧?

   PathGeometry pathGeometry = new PathGeometry();
   PathFigure pathFigure = new PathFigure();
   pathFigure.StartPoint = start;
   ArcSegment arc = new ArcSegment(end, new Size(radiusX, radiusY), 0.0, large, d, true);  //large & d corresponds to size & direction
   pathFigure.Segments.Add(arc);
   pathGeometry.Figures.Add(pathFigure);
   SolidColorBrush fill = new SolidColorBrush(color);
   drawingContext.DrawGeometry(fill, pen, pathGeometry);

我的代码生成输出:enter image description here

而我的要求就是这个:enter image description here

有没有办法完成这项工作? TIA。

1 个答案:

答案 0 :(得分:3)

当然,您只需要添加一个线段以与弧段一起使用。

   PathGeometry pathGeometry = new PathGeometry();
   PathFigure pathFigure = new PathFigure();
   pathFigure.StartPoint = start;
   ArcSegment arc = new ArcSegment(end, new Size(radiusX, radiusY), 0.0, large, d, true);  //large & d corresponds to size & direction
   pathFigure.Segments.Add(arc);

   //line segment takes the path to the origin
   LineSegment line = new LineSegment(new Point(originX, originY), true);
   pathFigure.Segments.Add(line );

   pathGeometry.Figures.Add(pathFigure);
   SolidColorBrush fill = new SolidColorBrush(color);
   drawingContext.DrawGeometry(fill, pen, pathGeometry);