终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

89 lines
3.1 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. namespace BPASmartClient.MilkWithTea.Control
  17. {
  18. /// <summary>
  19. /// CircularProgressBar.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class CircularProgressBar : UserControl
  22. {
  23. public CircularProgressBar()
  24. {
  25. InitializeComponent();
  26. UpdateValue(Percent * 3.6);
  27. }
  28. public double Percent
  29. {
  30. get { return (double)GetValue(PercentProperty); }
  31. set
  32. {
  33. SetValue(PercentProperty, value);
  34. UpdateValue(Percent * 3.6);
  35. }
  36. }
  37. //public static DependencyProperty PercentProperty => percentProperty;
  38. // Using a DependencyProperty as the backing store for Percent. This enables animation, styling, binding, etc...
  39. private static readonly DependencyProperty PercentProperty =
  40. DependencyProperty.Register("Percent", typeof(double), typeof(CircularProgressBar), new PropertyMetadata(default(double), new PropertyChangedCallback(OnPropertyChanged)));
  41. private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  42. {
  43. CircularProgressBar _cycleProgess = d as CircularProgressBar;
  44. _cycleProgess.UpdateValue(_cycleProgess.Percent * 3.6);
  45. }
  46. private void UpdateValue(double angle)
  47. {
  48. if (angle > 360) return;
  49. if (angle <= 0) return;
  50. int offset = 5;
  51. if (angle > 359) angle = 359.8;
  52. double radius = this.Width / 2 - offset;
  53. if (radius < 0) return;
  54. double b = radius * Math.Sin(angle * Math.PI / 180);
  55. double x = radius + b;
  56. double y = radius - radius * Math.Cos(angle * Math.PI / 180);
  57. double startPositionX = radius + offset;
  58. double startPositionY = offset;
  59. if (angle > 180)
  60. {
  61. //string Data = string.Format("M {0} 0 A {0} {0} 0 1 1 {1} {2}", radius, Math.Round(x, 2), Math.Round(y, 2));
  62. string Data = string.Format("M {0} {1} A {2} {2} 0 1 1 {3} {4}", startPositionX, startPositionY, radius, Math.Round(x, 2) + offset, Math.Round(y, 2) + offset);
  63. this.cyclePath.Data = Geometry.Parse(Data);
  64. }
  65. else
  66. {
  67. //string Data = string.Format("M {0} 0 A {0} {0} 0 0 1 {1} {2}", radius, Math.Round(x,2), Math.Round(y, 2));
  68. string Data = string.Format("M {0} {1} A {2} {2} 0 0 1 {3} {4}", startPositionX, startPositionY, radius, Math.Round(x, 2) + offset, Math.Round(y, 2) + offset);
  69. this.cyclePath.Data = Geometry.Parse(Data);
  70. }
  71. }
  72. }
  73. }