From 5859db79b71b50d8a156944908b33a20b351b22b Mon Sep 17 00:00:00 2001 From: iorebuild Date: Mon, 14 Oct 2024 00:04:23 +0800 Subject: [PATCH] asysnc mainimgbox --- 山海奇闻录/山海奇闻录/Views/MainView.axaml | 1 + 山海奇闻录/山海奇闻录/Views/MainView.axaml.cs | 45 +++++++++++++++++-- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/山海奇闻录/山海奇闻录/Views/MainView.axaml b/山海奇闻录/山海奇闻录/Views/MainView.axaml index dd30056..c2d4f94 100644 --- a/山海奇闻录/山海奇闻录/Views/MainView.axaml +++ b/山海奇闻录/山海奇闻录/Views/MainView.axaml @@ -61,6 +61,7 @@ Stretch="UniformToFill" /> + diff --git a/山海奇闻录/山海奇闻录/Views/MainView.axaml.cs b/山海奇闻录/山海奇闻录/Views/MainView.axaml.cs index dcccbb9..ede2a70 100644 --- a/山海奇闻录/山海奇闻录/Views/MainView.axaml.cs +++ b/山海奇闻录/山海奇闻录/Views/MainView.axaml.cs @@ -1,15 +1,23 @@ +using System; +using System.Threading; using System.Threading.Tasks; using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.Media; +using Avalonia.Threading; using 山海奇闻录.ViewModels; namespace 山海奇闻录.Views; public partial class MainView : UserControl { - public double WindowWidth; - public double WindowHeight; + private const int MainBoxNum = 3; + private int CurImgIndex; + + private Task backgroundTask; + + private double WindowWidth; + private double WindowHeight; public MainView() { @@ -55,6 +63,8 @@ public partial class MainView : UserControl InitLunBoTu(); InitPushWindow(); + + StartSwitchMainImageBox(); } private async void OpenPushWindowHandler(object? sender, RoutedEventArgs e) @@ -117,7 +127,36 @@ public partial class MainView : UserControl { await ClosePushWindowExec(); } - + + private void StartSwitchMainImageBox() + { + backgroundTask = Task.Run(async () => await BackgroundTaskAsync()); + } + + private async Task BackgroundTaskAsync() + { + int cnt = 0; + while (true) + { + await Task.Delay(1000); // 每秒执行一次 + // for (int i = 0; i < CurImgIndex; i++) + // { + // // 更新 UI + // Dispatcher.UIThread.InvokeAsync(() => + // { + // this.Fuck.Text = cnt.ToString(); + // cnt += 1; + // if (cnt >= 3) + // { + // cnt = 0; + // } + // }); + // + // + // } + } + } + //轮播图上一张 void MainImageBoxPre() {