wpf 画圆计算

2017-06-02 19:15:28来源:CSDN作者:Fanny_x人点击

 public static readonly DependencyProperty AngleProperty =
            DependencyProperty.Register("Angle", typeof(double), typeof(CircularProgressBar), new PropertyMetadata(120d, new PropertyChangedCallback(OnPropertyChanged)));

 

private static void OnPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)

        {
            CircularProgressBar circle = sender as CircularProgressBar;
            circle.RenderArc();
        }

        public void RenderArc()
        {
            Point startPoint = new Point(Radius, 0);
            Point endPoint = ComputeCartesianCoordinate(Angle, Radius);
            endPoint.X += Radius;
            endPoint.Y += Radius;

            pathRoot.Width = Radius * 2 + StrokeThickness;
            pathRoot.Height = Radius * 2 + StrokeThickness;


            //   pathRoot.Margin = new Thickness(StrokeThickness, StrokeThickness, 0, 0);

            bool largeArc = Angle > 180.0;

            Size outerArcSize = new Size(Radius, Radius);

            pathFigure.StartPoint = startPoint;

            if (startPoint.X == Math.Round(endPoint.X) && startPoint.Y == Math.Round(endPoint.Y))
                endPoint.X -= 0.01;

            arcSegment.Point = endPoint;
            arcSegment.Size = outerArcSize;
            arcSegment.IsLargeArc = largeArc;
        }

        private Point ComputeCartesianCoordinate(double angle, double radius)
        {
            // convert to radians
            double angleRad = (Math.PI / 180.0) * (angle - 90);

            double x = radius * Math.Cos(angleRad);
            double y = radius * Math.Sin(angleRad);

            return new Point(x, y);

        }


 private void DrawCircular()
        {
            //BeginCircleStoryBoard(180);

            Thread thread = new Thread(() =>
            {
                for (int i = 0; i < 101; i++)
                {
                    if (Application.Current != null)
                    {
                        Application.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            if (i == 50)
                            {
                                fadeinDevice();
                                fadeinUsb();
                            }
                            circularBorder.Percentage = i;
                        }));
                    }
                    Thread.Sleep(3);
                }
            });
            thread.Name = "DrawCircularThread";
            thread.Start();
        }

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台