DamagesViewModel.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using SWRIS.Dtos;
  2. using System.Collections.ObjectModel;
  3. using System.ComponentModel;
  4. namespace SWRIS.Models.ViewModel
  5. {
  6. public class DamagesViewModel : INotifyPropertyChanged
  7. {
  8. private RecordDto _record;
  9. private ObservableCollection<SensorModel> _sensors;
  10. private bool _isSummaryActive = true;
  11. private bool _isSensorSyncing;
  12. public RecordDto Record
  13. {
  14. get => _record;
  15. set
  16. {
  17. if (_record != value)
  18. {
  19. _record = value;
  20. OnPropertyChanged(nameof(Record));
  21. }
  22. }
  23. }
  24. public ObservableCollection<SensorModel> Sensors
  25. {
  26. get => _sensors;
  27. set
  28. {
  29. if (_sensors != value)
  30. {
  31. _sensors = value;
  32. OnPropertyChanged(nameof(Sensors));
  33. }
  34. }
  35. }
  36. public bool IsSummaryActive
  37. {
  38. get => _isSummaryActive;
  39. set
  40. {
  41. if (_isSummaryActive != value)
  42. {
  43. _isSummaryActive = value;
  44. OnPropertyChanged(nameof(IsSummaryActive));
  45. if (_isSummaryActive)
  46. {
  47. // 合值被选中:取消所有传感器的选中状态
  48. foreach (var sensor in Sensors)
  49. {
  50. sensor.IsActive = false;
  51. }
  52. }
  53. else if (!_isSensorSyncing)
  54. {
  55. // 合值被取消(用户主动操作):自动选中所有传感器
  56. foreach (var sensor in Sensors)
  57. {
  58. sensor.IsActive = true;
  59. }
  60. }
  61. }
  62. }
  63. }
  64. /// <summary>
  65. /// 标记当前是否由"选中传感器"联动取消合值,避免联动时反向自动选中所有传感器
  66. /// </summary>
  67. public bool IsSensorSyncing
  68. {
  69. get => _isSensorSyncing;
  70. set => _isSensorSyncing = value;
  71. }
  72. public event PropertyChangedEventHandler PropertyChanged;
  73. protected internal virtual void OnPropertyChanged(string propertyName)
  74. {
  75. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  76. }
  77. }
  78. }