fix: 使用 CommunityToolkit.Mvvm
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using CloudPrint.Client.Infrastructure;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace CloudPrint.Client.Models;
|
||||
|
||||
@@ -11,13 +11,22 @@ public enum PrintJobStatus
|
||||
Cancelled
|
||||
}
|
||||
|
||||
public sealed class PrintJob : ObservableObject
|
||||
public sealed partial class PrintJob : ObservableObject
|
||||
{
|
||||
private PrintJobStatus _status = PrintJobStatus.Pending;
|
||||
private int _progress;
|
||||
private string _errorMessage = string.Empty;
|
||||
private int? _windowsJobId;
|
||||
private string _windowsJobStatus = string.Empty;
|
||||
[ObservableProperty]
|
||||
private int? windowsJobId;
|
||||
|
||||
[ObservableProperty]
|
||||
private string windowsJobStatus = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(StatusText))]
|
||||
private PrintJobStatus status = PrintJobStatus.Pending;
|
||||
|
||||
[ObservableProperty]
|
||||
private string errorMessage = string.Empty;
|
||||
|
||||
private int progress;
|
||||
|
||||
public int Id { get; init; }
|
||||
public string JobNo { get; init; } = string.Empty;
|
||||
@@ -34,40 +43,10 @@ public sealed class PrintJob : ObservableObject
|
||||
public DateTime? StartedAt { get; set; }
|
||||
public DateTime? CompletedAt { get; set; }
|
||||
|
||||
public int? WindowsJobId
|
||||
{
|
||||
get => _windowsJobId;
|
||||
set => SetProperty(ref _windowsJobId, value);
|
||||
}
|
||||
|
||||
public string WindowsJobStatus
|
||||
{
|
||||
get => _windowsJobStatus;
|
||||
set => SetProperty(ref _windowsJobStatus, value);
|
||||
}
|
||||
|
||||
public PrintJobStatus Status
|
||||
{
|
||||
get => _status;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _status, value))
|
||||
{
|
||||
OnPropertyChanged(nameof(StatusText));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int Progress
|
||||
{
|
||||
get => _progress;
|
||||
set => SetProperty(ref _progress, Math.Clamp(value, 0, 100));
|
||||
}
|
||||
|
||||
public string ErrorMessage
|
||||
{
|
||||
get => _errorMessage;
|
||||
set => SetProperty(ref _errorMessage, value);
|
||||
get => progress;
|
||||
set => SetProperty(ref progress, Math.Clamp(value, 0, 100));
|
||||
}
|
||||
|
||||
public string StatusText => Status switch
|
||||
@@ -107,4 +86,4 @@ public sealed class PrintJob : ObservableObject
|
||||
Status = PrintJobStatus.Cancelled;
|
||||
CompletedAt = DateTime.Now;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user