初步添加事件服务

This commit is contained in:
2025-09-12 13:25:39 +08:00
parent 071347bc91
commit cb739f4cb9
11 changed files with 423 additions and 4 deletions

View File

@@ -3,6 +3,8 @@
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using DMS.Core.Enums;
using DMS.WPF.Events;
using DMS.WPF.Interfaces;
namespace DMS.WPF.ViewModels.Items;
@@ -12,6 +14,9 @@ namespace DMS.WPF.ViewModels.Items;
/// </summary>
public partial class DeviceItemViewModel : ObservableObject
{
// 用于访问事件服务的静态属性
public static IEventService EventService { get; set; }
public int Id { get; set; }
[ObservableProperty]
@@ -72,6 +77,19 @@ public partial class DeviceItemViewModel : ObservableObject
}
}
/// <summary>
/// 当IsActive属性改变时调用用于发布设备状态改变事件
/// </summary>
partial void OnIsActiveChanged(bool oldValue, bool newValue)
{
// 只有当设备ID有效且事件服务已初始化时才发布事件
if (Id > 0 && EventService != null)
{
// 发布设备状态改变事件
EventService.RaiseDeviceStatusChanged(this, new DeviceActiveChangedEventArgs(Id, Name, oldValue, newValue));
}
}
public ObservableCollection<VariableTableItemViewModel> VariableTables { get; set; } = new();
}