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,11 +11,20 @@ public enum PrinterStatus
|
||||
Unknown = 99
|
||||
}
|
||||
|
||||
public sealed class PrinterInfo : ObservableObject
|
||||
public sealed partial class PrinterInfo : ObservableObject
|
||||
{
|
||||
private PrinterStatus _status;
|
||||
private int _queueCount;
|
||||
private string _statusMessage = string.Empty;
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(DisplayText))]
|
||||
private int queueCount;
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(DisplayText))]
|
||||
private string statusMessage = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(StatusText))]
|
||||
[NotifyPropertyChangedFor(nameof(DisplayText))]
|
||||
private PrinterStatus status;
|
||||
|
||||
public int Id { get; init; }
|
||||
public string Name { get; init; } = string.Empty;
|
||||
@@ -24,40 +33,11 @@ public sealed class PrinterInfo : ObservableObject
|
||||
public string ApiKey { get; init; } = string.Empty;
|
||||
public DateTime? LastHeartbeat { get; set; }
|
||||
|
||||
public int QueueCount
|
||||
partial void OnQueueCountChanged(int value)
|
||||
{
|
||||
get => _queueCount;
|
||||
set
|
||||
if (value < 0)
|
||||
{
|
||||
if (SetProperty(ref _queueCount, Math.Max(0, value)))
|
||||
{
|
||||
OnPropertyChanged(nameof(DisplayText));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string StatusMessage
|
||||
{
|
||||
get => _statusMessage;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _statusMessage, value))
|
||||
{
|
||||
OnPropertyChanged(nameof(DisplayText));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PrinterStatus Status
|
||||
{
|
||||
get => _status;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _status, value))
|
||||
{
|
||||
OnPropertyChanged(nameof(StatusText));
|
||||
OnPropertyChanged(nameof(DisplayText));
|
||||
}
|
||||
QueueCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,4 +59,4 @@ public sealed class PrinterInfo : ObservableObject
|
||||
return $"{DisplayName}({StatusText}{queueText}{messageText})";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user