123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- using System.Windows.Media;
- namespace HistoryView.Controls;
- /// <summary>
- /// Interaction logic for HisProgressBar.xaml
- /// </summary>
- public partial class HisProgressBar : UserControl
- {
- public HisProgressBar()
- {
- InitializeComponent();
- }
- private BarData? _current;
- public BarData? CurrentData
- {
- get
- {
- lock (this)
- return _current;
- }
- set
- {
- lock (this)
- {
- _current = value;
- if (value is null)
- return;
- App.Current.Dispatcher.Invoke(() =>
- {
- for (int i = 0; i < RealtimeData.Count; i++)
- {
- if (i == RealtimeData.Count - 1)
- {
- RealtimeData[i].Value = value.Value < 3 ? 3 : value.Value;
- RealtimeData[i].Bursh = value.Bursh;
- break;
- }
- RealtimeData[i].Value = RealtimeData[i + 1].Value;
- RealtimeData[i].Bursh = RealtimeData[i + 1].Bursh;
- }
- });
- }
- }
- }
- public int RefreshRate
- {
- get { return (int)GetValue(RefreshRateProperty); }
- set { SetValue(RefreshRateProperty, value); }
- }
- public static readonly DependencyProperty RefreshRateProperty =
- DependencyProperty.Register("RefreshRate", typeof(int), typeof(HisProgressBar), new PropertyMetadata(1000));
- private ObservableCollection<BarData> RealtimeData
- {
- get { return (ObservableCollection<BarData>)GetValue(RealtimeDataProperty); }
- set { SetValue(RealtimeDataProperty, value); }
- }
- public static readonly DependencyProperty RealtimeDataProperty =
- DependencyProperty.Register("RealtimeData", typeof(ObservableCollection<BarData>), typeof(HisProgressBar), new PropertyMetadata(new ObservableCollection<BarData>()));
- public double CurrentValue
- {
- get { return (double)GetValue(CurrentValueProperty); }
- set { SetValue(CurrentValueProperty, value); }
- }
- public static readonly DependencyProperty CurrentValueProperty =
- DependencyProperty.Register("CurrentValue", typeof(double), typeof(HisProgressBar), new PropertyMetadata(0d, PropertyChangedCallback));
- private static void PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if (d is not HisProgressBar info)
- return;
- //double value = Math.Round(Convert.ToDouble(e.NewValue) / info.MaxValue, 1);
- lock (info)
- info.CurrentData = new((double)e.NewValue, info.WarningValue, info.AlarmValue);
- if (info.RealtimeData is null || info.RealtimeData.Count == 0)
- {
- info.RealtimeData ??= [];
- var width = info.Width / 3;
- for (int i = 0; i < width; i++)
- info.RealtimeData.Add(new(1, info.WarningValue, info.AlarmValue));
- }
- }
- public double MaxValue
- {
- get { return (double)GetValue(MaxValueProperty); }
- set { SetValue(MaxValueProperty, value); }
- }
- public static readonly DependencyProperty MaxValueProperty =
- DependencyProperty.Register("MaxValue", typeof(double), typeof(HisProgressBar), new PropertyMetadata(100d));
- public double WarningValue
- {
- get { return (double)GetValue(WarningValueProperty); }
- set { SetValue(WarningValueProperty, value); }
- }
- public static readonly DependencyProperty WarningValueProperty =
- DependencyProperty.Register("WarningValue", typeof(double), typeof(HisProgressBar), new PropertyMetadata(25d));
- public double AlarmValue
- {
- get { return (double)GetValue(AlarmValueProperty); }
- set { SetValue(AlarmValueProperty, value); }
- }
- public static readonly DependencyProperty AlarmValueProperty =
- DependencyProperty.Register("AlarmValue", typeof(double), typeof(HisProgressBar), new PropertyMetadata(75d));
- }
- public partial class BarData : ObservableObject
- {
- public BarData(double value, double warningValue, double alarmValue)
- {
- string hexString = "A0";
- this.Value = value;
- this.Bursh = new SolidColorBrush((Color)ColorConverter.ConvertFromString($"#{hexString}32CD32"));
- if (value > alarmValue || value < warningValue)
- {
- this.Bursh = new SolidColorBrush((Color)ColorConverter.ConvertFromString($"#{hexString}FF4040"));
- return;
- }
- //if (value >= warningValue)
- //{
- // this.Bursh = new SolidColorBrush((Color)ColorConverter.ConvertFromString($"#{hexString}FF8C00"));
- // return;
- //}
- }
- [ObservableProperty]
- private double _value;
- [ObservableProperty]
- private SolidColorBrush _bursh;
- }
|