初步添加事件服务
This commit is contained in:
@@ -44,9 +44,13 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable
|
||||
/// <summary>
|
||||
/// 初始化 <see cref="DevicesViewModel"/> 类的新实例。
|
||||
/// </summary>
|
||||
/// <param name="logger">日志记录器。</param>
|
||||
/// <param name="mapper">对象映射器。</param>
|
||||
/// <param name="dataStorageService">数据存储服务。</param>
|
||||
/// <param name="dialogService">对话框服务。</param>
|
||||
/// <param name="navigationService">导航服务。</param>
|
||||
/// <param name="wpfDataService">主数据服务。</param>
|
||||
/// <param name="deviceAppService">设备应用服务。</param>
|
||||
/// <param name="notificationService">通知服务。</param>
|
||||
public DevicesViewModel(IMapper mapper,IDataStorageService dataStorageService,
|
||||
IDialogService dialogService, INavigationService navigationService,
|
||||
IWPFDataService wpfDataService, IDeviceAppService deviceAppService,
|
||||
@@ -60,6 +64,9 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable
|
||||
_deviceAppService = deviceAppService;
|
||||
_notificationService = notificationService;
|
||||
Devices = _dataStorageService.Devices;
|
||||
|
||||
// 设置DeviceItemViewModel的静态服务引用
|
||||
DeviceItemViewModel.EventService = wpfDataService.EventService;
|
||||
}
|
||||
|
||||
|
||||
@@ -204,5 +211,15 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable
|
||||
|
||||
public async Task OnNavigatedToAsync(MenuItemViewModel menu)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void OnDeviceIsActiveChanged(object? sender, bool isActive)
|
||||
{
|
||||
if (sender is DeviceItemViewModel deviceItemViewModel)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user