using System.Collections.ObjectModel; using System.Windows.Threading; using CommunityToolkit.Mvvm.ComponentModel; using Seyounth.Hyosung.Data.Models; using Seyounth.Hyosung.Data.Models.Plc; using Seyounth.Hyosung.Data.Services; using Seyounth.Hyosung.Runtime; using Seyounth.Hyosung.Runtime.Models; namespace Seyounth.Hyosung.ViewModels; public partial class HomeViewModel : ObservableObject { [ObservableProperty] private StackStationModel _stack1; [ObservableProperty] private StackStationModel _stack2; [ObservableProperty] private ObservableCollection _varieties; [ObservableProperty] private List _yarnCarTypes; [ObservableProperty] private List _yarnCarSide; [ObservableProperty] private Variety _selectedVariety; [ObservableProperty] private PackLineOption _packLineOption; private readonly IHyosungRuntime _runtime; public HomeViewModel(IVarietyService varietyService, IHyosungRuntime runtime) { PackLineOption = runtime.PackLineOption; _runtime = runtime; _stack1 = _runtime.Stack1; _stack2 = _runtime.Stack2; _yarnCarTypes = new List(); _yarnCarTypes.Add("A"); _yarnCarTypes.Add("B"); _yarnCarTypes.Add("C"); _yarnCarTypes.Add("D"); _yarnCarSide = new(); _yarnCarSide.Add("正面"); _yarnCarSide.Add("反面"); _varieties = new ObservableCollection(varietyService.GetAll()); DispatcherTimer timer = new DispatcherTimer(); timer = new DispatcherTimer(); // 设置定时器间隔,这里设置为 1 秒,可根据实际需求调整 timer.Interval = TimeSpan.FromSeconds(1); // 为定时器的 Tick 事件添加处理方法 timer.Tick += Timer_Tick; // 启动定时器 timer.Start(); } private void Timer_Tick(object? sender, EventArgs e) { Stack1 = _runtime.Stack1; Stack2 = _runtime.Stack2; PackLineOption = _runtime.PackLineOption; } }