From 9ba65803f018edf12ce2800559bc9b3acfc3e6f8 Mon Sep 17 00:00:00 2001 From: wxl0430 <141288415+wxl0430@users.noreply.github.com> Date: Sun, 2 Mar 2025 21:06:32 +0800 Subject: [PATCH] Add files via upload --- .../Stations/Zibo/SecondaryScreenViewModel.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 CRSim/ViewModels/Windows/Stations/Zibo/SecondaryScreenViewModel.cs diff --git a/CRSim/ViewModels/Windows/Stations/Zibo/SecondaryScreenViewModel.cs b/CRSim/ViewModels/Windows/Stations/Zibo/SecondaryScreenViewModel.cs new file mode 100644 index 0000000..9750834 --- /dev/null +++ b/CRSim/ViewModels/Windows/Stations/Zibo/SecondaryScreenViewModel.cs @@ -0,0 +1,40 @@ +namespace CRSim.ViewModels.Zibo +{ + public class SecondaryScreenViewModel : ScreenViewModel + { + public ObservableCollection Screen { get; private set; } = []; + public SecondaryScreenViewModel(ITimeService timeService, ISettingsService settingsService) + : base(timeService, settingsService) + { + Text = $"开车前{settingsService.GetSettings().StopCheckInAdvanceDuration.TotalMinutes}分钟停止检票"; + ItemsPerPage = 18; + PageCount = 1; + timeService.RefreshSecondsElapsed += RefreshDisplay; + Initialize(); + } + private async void Initialize() + { + await WaitForDataLoadAsync(); + RefreshDisplay(null,null); + } + private void RefreshDisplay(object? sender, EventArgs e) + { + Application.Current.Dispatcher.Invoke(() => + { + int pageCount = (int)Math.Ceiling((double)TrainInfo.Count / (ItemsPerPage * PageCount)); + Screen.Clear(); + int startIndex = CurrentPageIndex * ItemsPerPage * PageCount; + var Items = TrainInfo.Skip(startIndex).Take(ItemsPerPage).ToList(); + while (Items.Count < ItemsPerPage) // Fill up with new object() if not enough items + { + Items.Add(new TrainInfo()); + } + foreach (var item in Items) + { + Screen.Add(item); + } + CurrentPageIndex = CurrentPageIndex + 1 >= Math.Min(_settings.MaxPages, pageCount) ? 0 : CurrentPageIndex + 1; + }); + } + } +}