using System.Threading; using AIK.Common.Language; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Threading; namespace AIK.Views.UIViewModels { /// /// 专用于进度弹窗的 ViewModel,仅管理 UI 状态,不执行业务逻辑。 /// public partial class ProgressDialogViewModel : ObservableObject { private readonly CancellationTokenSource _cts = new(); public CancellationToken CancellationToken => _cts.Token; [ObservableProperty] private string _title = string.Empty; [ObservableProperty] private string _message = string.Empty; [ObservableProperty] private double _progress = 0.0; [ObservableProperty] private bool _isIndeterminate = false; [ObservableProperty] private bool _isCancelButtonVisible = true; [ObservableProperty] private bool _isCompleted; [ObservableProperty] private double _timeSecond; [ObservableProperty] private string _timeTotalText = string.Empty; public ProgressDialogViewModel( string title = "正在烧录", string message = "正在烧录...", bool showCancel = true) { title = title == "正在烧录" ? AiKLanguage.LanguageKey.GetValueOrDefault("DialogBurningTitle") ?? string.Empty : title; message = message == "正在烧录..." ? AiKLanguage.LanguageKey.GetValueOrDefault("DialogBurningMessage") ?? string.Empty : message; Title = title; Message = message; IsCancelButtonVisible = showCancel; Progress = 0.00; IsCompleted = false; } /// /// 由外部(如 ModalDialogService)调用,用于更新进度 /// public void ReportProgress(double value) { Progress = value; IsIndeterminate = false; } [RelayCommand] private void Cancel() { _cts.Cancel(); } } }