wpf 前台繪制圓弧很簡單,如:<Path x:Name="path_data" Stroke="#FFE23838" StrokeThickness="1" Data="M 100,0 A 50,100 0 0 0 100,200"></Path>
注解:M 起始點 (100,0) A 尺寸(X50,Y100半徑) 圓弧旋轉角度值(0) 優勢弧的標記(否,弧角度小於180) 正負角度標記(0 逆時針畫圓) 結束點(100,200)
所以畫出的圖形為
由於項目需要,需要在后台動態繪制圓弧,切入點ArcSegment,一步步摸索出繪制方法。
ArcSegment(Point point, Size size, double rotationAngle, bool isLargeArc, SweepDirection sweepDirection, bool isStroked);
由於Point是結束點,需要定義起始點StartPoint,嘗試還真有這個屬性,后台繪制就出來了。代碼如下
Path path = new Path(); PathGeometry pathGeometry = new PathGeometry(); ArcSegment arc = new ArcSegment(new Point(100, 200), new Size(50, 100), 0, false, SweepDirection.Counterclockwise, true); PathFigure figure = new PathFigure(); figure.StartPoint = new Point(100, 0); figure.Segments.Add(arc); pathGeometry.Figures.Add(figure); path.Data = pathGeometry; path.Stroke = Brushes.Orange; canvas.Children.Add(path);
