alielie
2026-06-15 f08871fe7d148d667f2f11f80f64de71a0d9504c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using HMI.Base;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
 
namespace WPFProject
{
    /// <summary>
    /// ResourceListener.xaml 的交互逻辑
    /// </summary>
    public partial class ResourceUI : NotifyControl
    {
        private string cpuRate;
        public string CpuRate
        {
            get => cpuRate;
            set
            {
                Set(ref cpuRate, value);
            }
        }
 
        private string remRate;
        public string RemRate
        {
            get => remRate;
            set
            {
                Set(ref remRate, value);
            }
        }
 
        private string totalCpuRate;
        public string TotalCpuRate
        {
            get => totalCpuRate;
            set
            {
                Set(ref totalCpuRate, value);
            }
        }
 
        private string totalRemRate;
        public string TotalRemRate
        {
            get => totalRemRate;
            set
            {
                Set(ref totalRemRate, value);
            }
        }
 
        public ResourceUI()
        {
            DataContext = this;
            InitializeComponent();
        }
 
        public void Refresh(object sender, RunTimeState state)
        {
            Dispatcher.BeginInvoke(() =>
            {
                CpuRate = $"{state.cpuRate:F1}%";
                SetColor(state.cpuRate, l1);
                RemRate = $"{state.remRate:F1}%";
                SetColor(state.remRate, l2);
 
                TotalCpuRate = $"{state.totalCpuRate:F1}%";
                SetColor(state.totalCpuRate, l3);
                TotalRemRate = $"{state.totalRemRate:F1}%";
                SetColor(state.totalRemRate, l4);
            }, System.Windows.Threading.DispatcherPriority.Normal);
        }
 
        private void SetColor(double val, Label label)
        {
            if (val > 80)
            {
                label.Background = Brushes.Red;
            }
            else if (val > 60)
            {
                label.Background = Brushes.Orange;
            }
            else
            {
                label.Background = Application.Current.FindResource("SecondPrimaryColor") as Brush;
            }
        }
    }
}