asysnc mainimgbox

This commit is contained in:
iorebuild 2024-10-14 00:04:23 +08:00
parent e872682d37
commit 5859db79b7
2 changed files with 43 additions and 3 deletions

View File

@ -61,6 +61,7 @@
Stretch="UniformToFill" />
</StackPanel>
</Border>
<TextBlock x:Name="Fuck" Text="v"/>
</Grid>
</Grid>
<!-- <StackPanel> -->

View File

@ -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)
@ -118,6 +128,35 @@ 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()
{