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" /> Stretch="UniformToFill" />
</StackPanel> </StackPanel>
</Border> </Border>
<TextBlock x:Name="Fuck" Text="v"/>
</Grid> </Grid>
</Grid> </Grid>
<!-- <StackPanel> --> <!-- <StackPanel> -->

View File

@ -1,15 +1,23 @@
using System;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.Media; using Avalonia.Media;
using Avalonia.Threading;
using .ViewModels; using .ViewModels;
namespace .Views; namespace .Views;
public partial class MainView : UserControl public partial class MainView : UserControl
{ {
public double WindowWidth; private const int MainBoxNum = 3;
public double WindowHeight; private int CurImgIndex;
private Task backgroundTask;
private double WindowWidth;
private double WindowHeight;
public MainView() public MainView()
{ {
@ -55,6 +63,8 @@ public partial class MainView : UserControl
InitLunBoTu(); InitLunBoTu();
InitPushWindow(); InitPushWindow();
StartSwitchMainImageBox();
} }
private async void OpenPushWindowHandler(object? sender, RoutedEventArgs e) private async void OpenPushWindowHandler(object? sender, RoutedEventArgs e)
@ -117,7 +127,36 @@ public partial class MainView : UserControl
{ {
await ClosePushWindowExec(); 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() void MainImageBoxPre()
{ {