using System.Collections.Specialized; using System.Windows; using XP.App.ViewModels; using XP.Common.Logging.Interfaces; using XP.Hardware.Plc.Abstractions; using XP.Hardware.Plc.Services; using XP.Hardware.PLC.Configs; namespace XP.App.Views { /// /// ISignalDataService DEMO 窗口 /// public partial class SignalDataDemoWindow : Window { public SignalDataDemoWindow( PlcService plcService, ISignalDataService signalService, ConfigLoader configLoader, ILoggerService logger) { InitializeComponent(); var vm = new SignalDataDemoViewModel(plcService, signalService, configLoader, logger); DataContext = vm; if (Application.Current?.MainWindow != null) Icon = Application.Current.MainWindow.Icon; // 日志自动滚动 vm.LogEntries.CollectionChanged += (s, e) => { if (e.Action == NotifyCollectionChangedAction.Add && vm.LogEntries.Count > 0) { Dispatcher.InvokeAsync(() => { LogListBox.ScrollIntoView(vm.LogEntries[vm.LogEntries.Count - 1]); }, System.Windows.Threading.DispatcherPriority.Background); } }; } } }