using DyeingComputer.ViewModel; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Windows.Threading; using static System.Net.WebRequestMethods; namespace DyeingComputer.View { /// /// EquipmentSimulationView.xaml 的交互逻辑 /// public partial class EquipmentSimulationView : UserControl, INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string propertyName) { if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } public void RaisePropertyChanged(string propertyName) { if (PropertyChanged != null) { if (propertyName != null) { PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } } public EquipmentSimulationView() { InitializeComponent(); DataContext = this; CountDown(); } bool _ID3007, _ID3008,_ID3020; public bool ID3007 { get => _ID3007; set { _ID3007 = value; OnPropertyChanged("ID3007"); } } public bool ID3008 { get => _ID3008; set { _ID3008 = value; OnPropertyChanged("ID3008"); } } public bool ID3020 { get => _ID3020; set { _ID3020 = value; OnPropertyChanged("ID3020"); } } void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件1S { M_T.Text = string.Format(" {0:###.#}", Convert.ToDouble(MainWindowViewModel.Selet_dtm("1010"))) + "°C";//主缸温度 M_L.Text = string.Format("{0:D4}", Convert.ToInt16(MainWindowViewModel.Selet_dtm("1015"))) + "L";//主缸水 S1_T.Text = string.Format(" {0:###.#}", Convert.ToDouble(MainWindowViewModel.Selet_dtm("1012"))) + "°C";//缸1温度 S1_L.Text = string.Format("{0:D4}", Convert.ToInt16(MainWindowViewModel.Selet_dtm("1017"))) + "L";//缸1水 S2_T.Text = string.Format(" {0:###.#}", Convert.ToDouble(MainWindowViewModel.Selet_dtm("1013"))) + "°C";//缸2温度 S2_L.Text = string.Format("{0:D4}", Convert.ToInt16(MainWindowViewModel.Selet_dtm("1018"))) + "L";//缸2水 } public void CountDown() { DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每1秒调用一次Tick { Interval = TimeSpan.FromSeconds(2)//秒 }; timer1s.Tick += Tick_Event_1S; timer1s.Start(); } private void ID3007_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { ID3007 = !ID3007; } private void ID3008_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { ID3008 = !ID3008; } private void ID3020_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { ID3020 = !ID3020; } } }