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;
|
}
|
}
|
}
|
}
|