RingProgress.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Globalization;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Controls.Primitives;
  9. using System.Windows.Data;
  10. using System.Windows.Media;
  11. using System.Windows;
  12. namespace Venus_Themes.CustomControls
  13. {
  14. public class RingProgress : RangeBase
  15. {
  16. static RingProgress()
  17. {
  18. DefaultStyleKeyProperty.OverrideMetadata(typeof(RingProgress), new FrameworkPropertyMetadata(typeof(RingProgress)));
  19. }
  20. #region StrokeThickness 圆环描边宽度
  21. public static readonly DependencyProperty StrokeThicknessProperty =
  22. DependencyProperty.Register("StrokeThickness", typeof(double), typeof(RingProgress), new PropertyMetadata(10d));
  23. public double StrokeThickness
  24. {
  25. get { return (double)GetValue(StrokeThicknessProperty); }
  26. set { SetValue(StrokeThicknessProperty, value); }
  27. }
  28. #endregion
  29. #region Stroke 圆环描边颜色
  30. public static readonly DependencyProperty StrokeProperty =
  31. DependencyProperty.Register("Stroke", typeof(Brush), typeof(RingProgress), new PropertyMetadata(Brushes.Red));
  32. public Brush Stroke
  33. {
  34. get { return (Brush)GetValue(StrokeProperty); }
  35. set { SetValue(StrokeProperty, value); }
  36. }
  37. #endregion
  38. }
  39. internal static class RingProgressExtension
  40. {
  41. /// <summary>
  42. /// 角度转为弧度
  43. /// </summary>
  44. /// <param name="a"></param>
  45. /// <returns></returns>
  46. public static double AngleToArc(this double a)
  47. {
  48. return Math.PI * a / 180;
  49. }
  50. /// <summary>
  51. /// 角度及半径计算坐标点位置
  52. /// </summary>
  53. /// <param name="a"></param>
  54. /// <param name="radius"></param>
  55. /// <param name="offset"></param>
  56. /// <returns></returns>
  57. public static Point AngleToPoint(this double a, double radius, double offset = 0)
  58. {
  59. return new Point(Math.Cos(a.AngleToArc()) * radius + radius + offset, Math.Sin(a.AngleToArc()) * radius + radius + offset);
  60. }
  61. }
  62. }