From 2a60c070e913515d9b4adcae2cb1d064fad32f2f Mon Sep 17 00:00:00 2001 From: wxl0430 <141288415+wxl0430@users.noreply.github.com> Date: Mon, 3 Mar 2025 14:59:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E6=B5=8E=E5=8D=97?= =?UTF-8?q?=E8=A5=BF=E7=AB=99=E7=9A=84=E5=95=86=E5=8A=A1=E5=BA=A7=E5=80=99?= =?UTF-8?q?=E8=BD=A6=E5=AE=A4=E6=98=BE=E7=A4=BA=E5=B1=8F=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Jinanxi/PrimaryScreenViewModel.cs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 CRSim/ViewModels/Windows/Stations/Jinanxi/PrimaryScreenViewModel.cs diff --git a/CRSim/ViewModels/Windows/Stations/Jinanxi/PrimaryScreenViewModel.cs b/CRSim/ViewModels/Windows/Stations/Jinanxi/PrimaryScreenViewModel.cs new file mode 100644 index 0000000..199a205 --- /dev/null +++ b/CRSim/ViewModels/Windows/Stations/Jinanxi/PrimaryScreenViewModel.cs @@ -0,0 +1,41 @@ +namespace CRSim.ViewModels.Jinanxi +{ + public class PrimaryScreenViewModel : ScreenViewModel + { + public ObservableCollection Screen { get; private set; } = []; + public PrimaryScreenViewModel(ITimeService timeService, ISettingsService settingsService) + : base(timeService, settingsService) + { + Text = $"济 南 西 站 欢 迎 您"; + ItemsPerPage = 9; + 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; + }); + } + } +}