终端一体化运控平台
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.
 
 
 

174 lines
6.4 KiB

  1. using BPA.Helper;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Collections.ObjectModel;
  5. using System.Diagnostics;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Navigation;
  17. using System.Windows.Shapes;
  18. namespace BPASmartClient.CustomResource.UserControls
  19. {
  20. /// <summary>
  21. /// RankingList.xaml 的交互逻辑
  22. /// </summary>
  23. public partial class RankingList : UserControl
  24. {
  25. public RankingList()
  26. {
  27. InitializeComponent();
  28. this.Loaded += (s, o) =>
  29. {
  30. Refresh();
  31. ItemSources.ToList().ForEach(item => { item.ValueChange = new Action(() => { Refresh(); }); });
  32. };
  33. }
  34. private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as RankingList)?.Refresh();
  35. private void Refresh()
  36. {
  37. ObservableCollection<ItemPilotInfo> iCPoints = new ObservableCollection<ItemPilotInfo>();
  38. var max = ItemSources.Max(p => p.Value);
  39. ItemSources.OrderByDescending(p => p.Value).ToList().ForEach(item =>
  40. {
  41. iCPoints.Add(new ItemPilotInfo()
  42. {
  43. Name = item.Name,
  44. Value = item.Value,
  45. Width = ((double)item.Value).Scale(max + 30, 0, this.grid.ColumnDefinitions[1].ActualWidth - 30, 0),
  46. });
  47. });
  48. Application.Current.Dispatcher.Invoke(() =>
  49. {
  50. this.ic1.ItemsSource = iCPoints;
  51. this.ic2.ItemsSource = iCPoints;
  52. });
  53. }
  54. /// <summary>
  55. /// 进度条的高度
  56. /// </summary>
  57. public int LinHeight
  58. {
  59. get { return (int)GetValue(LinHeightProperty); }
  60. set { SetValue(LinHeightProperty, value); }
  61. }
  62. public static readonly DependencyProperty LinHeightProperty =
  63. DependencyProperty.Register("LinHeight", typeof(int), typeof(RankingList),
  64. new PropertyMetadata(10));
  65. /// <summary>
  66. /// 进度条的圆角度
  67. /// </summary>
  68. public CornerRadius BarCornerRadius
  69. {
  70. get { return (CornerRadius)GetValue(BarCornerRadiusProperty); }
  71. set { SetValue(BarCornerRadiusProperty, value); }
  72. }
  73. public static readonly DependencyProperty BarCornerRadiusProperty =
  74. DependencyProperty.Register("BarCornerRadius", typeof(CornerRadius), typeof(RankingList),
  75. new PropertyMetadata(new CornerRadius(5d)));
  76. /// <summary>
  77. /// 进度条之间的间隔
  78. /// </summary>
  79. public Thickness BarInterval
  80. {
  81. get { return (Thickness)GetValue(BarIntervalProperty); }
  82. set { SetValue(BarIntervalProperty, value); }
  83. }
  84. public static readonly DependencyProperty BarIntervalProperty =
  85. DependencyProperty.Register("BarInterval", typeof(Thickness), typeof(RankingList),
  86. new PropertyMetadata(new Thickness(5d)));
  87. /// <summary>
  88. /// 数值显示单位
  89. /// </summary>
  90. public string Unit
  91. {
  92. get { return (string)GetValue(UnitProperty); }
  93. set { SetValue(UnitProperty, value); }
  94. }
  95. public static readonly DependencyProperty UnitProperty =
  96. DependencyProperty.Register("Unit", typeof(string), typeof(RankingList),
  97. new PropertyMetadata("Unit"));
  98. /// <summary>
  99. /// 数据集合
  100. /// </summary>
  101. public ObservableCollection<BPAPilotInfo> ItemSources
  102. {
  103. get { return Application.Current.Dispatcher.Invoke(() => { return (ObservableCollection<BPAPilotInfo>)GetValue(ItemSourcesProperty); }); }
  104. set { SetValue(ItemSourcesProperty, value); }
  105. }
  106. public static readonly DependencyProperty ItemSourcesProperty =
  107. DependencyProperty.Register("ItemSources", typeof(ObservableCollection<BPAPilotInfo>), typeof(RankingList),
  108. new PropertyMetadata(default, new PropertyChangedCallback(OnPropertyChanged)));
  109. /// <summary>
  110. /// 进度条颜色
  111. /// </summary>
  112. public Brush ProgressBarColor
  113. {
  114. get { return (Brush)GetValue(ProgressBarColorProperty); }
  115. set { SetValue(ProgressBarColorProperty, value); }
  116. }
  117. public static readonly DependencyProperty ProgressBarColorProperty =
  118. DependencyProperty.Register("ProgressBarColor", typeof(Brush), typeof(RankingList),
  119. new PropertyMetadata(Brushes.Orange));
  120. //private void br_SizeChanged(object sender, SizeChangedEventArgs e)
  121. //{
  122. // Border border = (Border)sender;
  123. // if (border.Width is double.NaN) return;
  124. // DoubleAnimation da = new DoubleAnimation(border.Width, new Duration(TimeSpan.FromMilliseconds(500)));//指定动画的值
  125. // border.BeginAnimation(Border.WidthProperty, da);//指定动画对象
  126. // //DoubleAnimation widthAnimation = new DoubleAnimation();
  127. // //widthAnimation.From = 100; // 起始值
  128. // //widthAnimation.To = 300; // 结束值
  129. // //widthAnimation.Duration = new Duration(TimeSpan.FromSeconds(2)); // 动画长度
  130. // //Storyboard storyboard = new Storyboard();
  131. // //storyboard.Children.Add(widthAnimation);
  132. // //Storyboard.SetTarget(widthAnimation, sender as Border);
  133. // //Storyboard.SetTargetProperty(widthAnimation, new PropertyPath(Button.WidthProperty));
  134. // //storyboard.Begin();
  135. //}
  136. }
  137. public class BPAPilotInfo : NotifyBase
  138. {
  139. public string Name { get { return _mName; } set { _mName = value; OnPropertyChanged(); } }
  140. private string _mName;
  141. public float Value { get { return _mValue; } set { _mValue = value; OnPropertyChanged(); ValueChange?.Invoke(); } }
  142. private float _mValue;
  143. public Action ValueChange { get; set; }
  144. }
  145. public class ItemPilotInfo : BPAPilotInfo
  146. {
  147. public double Width { get { return _mWidth; } set { _mWidth = value; OnPropertyChanged(); } }
  148. private double _mWidth;
  149. }
  150. }