This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace PLCDataMonitor
|
||||
{
|
||||
@@ -19,21 +20,66 @@ namespace PLCDataMonitor
|
||||
public event EventHandler PauseRequested;
|
||||
public event EventHandler ResumeRequested;
|
||||
|
||||
// 【修改点 2】合并点击逻辑
|
||||
private void PauseButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
PauseRequested?.Invoke(this, EventArgs.Empty);
|
||||
string currentContent = PauseButton.Content.ToString();
|
||||
|
||||
if (currentContent == "暂停")
|
||||
{
|
||||
// 当前是运行状态,点击后变为暂停
|
||||
PauseRequested?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
// 立即更新按钮样式为“继续”
|
||||
PauseButton.Content = "继续";
|
||||
PauseButton.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#27AE60")); // 绿色
|
||||
}
|
||||
else
|
||||
{
|
||||
// 当前是暂停状态,点击后变为继续
|
||||
ResumeRequested?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
// 立即更新按钮样式为“暂停”
|
||||
PauseButton.Content = "暂停";
|
||||
PauseButton.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#E67E22")); // 橙色
|
||||
}
|
||||
}
|
||||
|
||||
private void ResumeButton_Click(object sender, RoutedEventArgs e)
|
||||
//private void ResumeButton_Click(object sender, RoutedEventArgs e)
|
||||
//{
|
||||
// ResumeRequested?.Invoke(this, EventArgs.Empty);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
// 【新增】供 MainWindow 调用的方法,以防 PLC 状态自行变化导致按钮状态不同步
|
||||
public void SetButtonState(bool isPaused)
|
||||
{
|
||||
ResumeRequested?.Invoke(this, EventArgs.Empty);
|
||||
if (isPaused)
|
||||
{
|
||||
PauseButton.Content = "继续";
|
||||
PauseButton.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#27AE60"));
|
||||
}
|
||||
else
|
||||
{
|
||||
PauseButton.Content = "暂停";
|
||||
PauseButton.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#E67E22"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void UpdateAlarms(string alarmMessage)
|
||||
{
|
||||
try
|
||||
{
|
||||
Dispatcher.Invoke(() => // 更新滚动报警控件的文本
|
||||
AlarmScrollingCtrl.Text = alarmMessage);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
Dispatcher.Invoke(() => // 更新滚动报警控件的文本
|
||||
AlarmScrollingCtrl.Text = alarmMessage);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新数据显示
|
||||
|
||||
Reference in New Issue
Block a user