DashBoardMainViewModel.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. namespace DashBoard.ViewModel;
  2. internal partial class DashBoardMainViewModel : ObservableObject
  3. {
  4. public DashBoardMainViewModel(DeviceCollection deviceCollection, IDialogService dialogService)
  5. {
  6. this._DeviceCollection = deviceCollection;
  7. this._DialogService = dialogService;
  8. deviceCollection.DeviceList.CollectionChanged += DeviceList_CollectionChanged;
  9. this.DeviceList_CollectionChanged(deviceCollection.DeviceList, null);
  10. }
  11. private void DeviceList_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs? e)
  12. {
  13. if (sender is not ObservableDictionary<Guid, DeviceInfo_VM> deviceList)
  14. return;
  15. this.Devices.Clear();
  16. foreach (DeviceInfo_VM device in deviceList.Values)
  17. {
  18. this.Devices[device.DeviceModel] ??= [];
  19. this.Devices[device.DeviceModel].Add(device);
  20. }
  21. }
  22. private readonly IDialogService _DialogService;
  23. private readonly DeviceCollection _DeviceCollection;
  24. [ObservableProperty]
  25. private ObservableDictionary<DeviceModel, ObservableCollection<DeviceInfo_VM>> _Devices = [];
  26. }