feat: add mvvm demo.

This commit is contained in:
Dong Bin
2025-02-24 19:15:55 +08:00
parent b20137e8aa
commit aa4507c9c8
5 changed files with 138 additions and 1 deletions

View File

@@ -0,0 +1,38 @@
using System;
using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
using Irihi.Avalonia.Shared.Contracts;
namespace Ursa.Demo.ViewModels;
public partial class SplashViewModel: ObservableObject, IDialogContext
{
[ObservableProperty] private double _progress;
private Random _r = new();
public SplashViewModel()
{
DispatcherTimer.Run(OnUpdate, TimeSpan.FromMilliseconds(200), DispatcherPriority.Default);
}
private bool OnUpdate()
{
Progress += 10 * _r.NextDouble();
if (Progress <= 100)
{
return true;
}
else
{
RequestClose?.Invoke(this, null);
return false;
}
}
public void Close()
{
RequestClose?.Invoke(this, null);
}
public event EventHandler<object?>? RequestClose;
}