コード例 #1
0
        /// <summary>
        /// Constructs a path that represents this pie segment
        /// </summary>
        /// <returns></returns>
        private Path ConstructPath()
        {
            if (WedgeAngle >= 360)
            {
                Path path = new Path()
                {
                    Fill            = this.Fill,
                    Stroke          = this.Stroke,
                    StrokeThickness = 1,
                    Data            = new GeometryGroup()
                    {
                        FillRule = System.Windows.Media.FillRule.EvenOdd,
                        Children = new GeometryCollection()
                        {
                            new EllipseGeometry()
                            {
                                Center  = new Point(CentreX, CentreY),
                                RadiusX = Radius,
                                RadiusY = Radius
                            },
                            new EllipseGeometry()
                            {
                                Center  = new Point(CentreX, CentreY),
                                RadiusX = InnerRadius,
                                RadiusY = InnerRadius
                            }
                        },
                    }
                };
                return(path);
            }



            Point startPoint = new Point(CentreX, CentreY);

            Point innerArcStartPoint = UtilsHelper.ComputeCartesianCoordinate(RotationAngle, InnerRadius);

            innerArcStartPoint.Offset(CentreX, CentreY);
            Point innerArcEndPoint = UtilsHelper.ComputeCartesianCoordinate(RotationAngle + WedgeAngle, InnerRadius);

            innerArcEndPoint.Offset(CentreX, CentreY);
            Point outerArcStartPoint = UtilsHelper.ComputeCartesianCoordinate(RotationAngle, Radius);

            outerArcStartPoint.Offset(CentreX, CentreY);
            Point outerArcEndPoint = UtilsHelper.ComputeCartesianCoordinate(RotationAngle + WedgeAngle, Radius);

            outerArcEndPoint.Offset(CentreX, CentreY);

            bool largeArc     = WedgeAngle > 180.0;
            Size outerArcSize = new Size(Radius, Radius);
            Size innerArcSize = new Size(InnerRadius, InnerRadius);

            PathFigure figure = new PathFigure()
            {
                StartPoint = innerArcStartPoint,
                Segments   = new PathSegmentCollection()
                {
                    new LineSegment()
                    {
                        Point = outerArcStartPoint
                    },
                    new ArcSegment()
                    {
                        Point          = outerArcEndPoint,
                        Size           = outerArcSize,
                        IsLargeArc     = largeArc,
                        SweepDirection = SweepDirection.Clockwise,
                        RotationAngle  = 0
                    },
                    new LineSegment()
                    {
                        Point = innerArcEndPoint
                    },
                    new ArcSegment()
                    {
                        Point          = innerArcStartPoint,
                        Size           = innerArcSize,
                        IsLargeArc     = largeArc,
                        SweepDirection = SweepDirection.Counterclockwise,
                        RotationAngle  = 0
                    }
                }
            };

            return(new Path()
            {
                Fill = this.Fill,
                Stroke = this.Stroke,
                StrokeThickness = 1,
                Data = new PathGeometry()
                {
                    Figures = new PathFigureCollection()
                    {
                        figure
                    }
                }
            });
        }