终端一体化运控平台
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

76 wiersze
2.4 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  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.CustomResource.UserControls
  17. {
  18. /// <summary>
  19. /// CircularDiagram.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class CircularDiagram : UserControl
  22. {
  23. public CircularDiagram()
  24. {
  25. InitializeComponent();
  26. this.Loaded += (s, e) => { sData = this.path.Data.ToString(); Refresh(); };
  27. }
  28. string sData = string.Empty;
  29. private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  30. {
  31. (d as CircularDiagram)?.Refresh();
  32. }
  33. private void Refresh()
  34. {
  35. if (Value <= 0)
  36. {
  37. this.path.Visibility = Visibility.Collapsed;
  38. this.tb.Text = "0%";
  39. }
  40. else
  41. {
  42. var datas = sData.Split('z');
  43. if (int.TryParse(Math.Round(Value * 0.36f).ToString(), out int temp))
  44. {
  45. if (temp >= 0 && temp <= datas.Length - 1)
  46. {
  47. StringBuilder sb = new StringBuilder();
  48. datas[0..temp].ToList()?.ForEach(item =>
  49. {
  50. sb.Append($"{item}z");
  51. });
  52. var converter = TypeDescriptor.GetConverter(typeof(Geometry));
  53. this.path.Data = (Geometry)converter.ConvertFrom(sb.ToString());
  54. }
  55. }
  56. this.path.Visibility = Visibility.Visible;
  57. this.tb.Text = $"{Value}%";
  58. }
  59. }
  60. public int Value
  61. {
  62. get { return (int)GetValue(ValueProperty); }
  63. set { SetValue(ValueProperty, value); }
  64. }
  65. public static readonly DependencyProperty ValueProperty =
  66. DependencyProperty.Register("Value", typeof(int), typeof(CircularDiagram),
  67. new PropertyMetadata(0, new PropertyChangedCallback(OnPropertyChanged)));
  68. }
  69. }