SingleSequenceActionGroup.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.ComponentModel;
  5. using System.Linq;
  6. using System.Runtime.CompilerServices;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace Team.FFFeederService.Models
  10. {
  11. /// <summary>
  12. /// 一个序列集
  13. /// </summary>
  14. public class SingleSequenceActionGroup : INotifyPropertyChanged
  15. {
  16. private ObservableCollection<SingleSequenceAction> _SingleSequenceActions;
  17. public ObservableCollection<SingleSequenceAction> SingleSequenceActions
  18. {
  19. get { return _SingleSequenceActions; }
  20. set { SetProperty(ref _SingleSequenceActions,value); }
  21. }
  22. private int _PartCntMax;
  23. /// <summary>
  24. /// 震动平台零件极限值
  25. /// </summary>
  26. public int PartCntMax
  27. {
  28. get { return _PartCntMax; }
  29. set { SetProperty(ref _PartCntMax, value); }
  30. }
  31. #region 属性更改通知
  32. /// <summary>
  33. /// Occurs when a property value changes.
  34. /// </summary>
  35. public event PropertyChangedEventHandler PropertyChanged;
  36. /// <summary>
  37. /// Checks if a property already matches a desired value. Sets the property and
  38. /// notifies listeners only when necessary.
  39. /// </summary>
  40. /// <typeparam name="T">Type of the property.</typeparam>
  41. /// <param name="storage">Reference to a property with both getter and setter.</param>
  42. /// <param name="value">Desired value for the property.</param>
  43. /// <param name="propertyName">Name of the property used to notify listeners. This
  44. /// value is optional and can be provided automatically when invoked from compilers that
  45. /// support CallerMemberName.</param>
  46. /// <returns>True if the value was changed, false if the existing value matched the
  47. /// desired value.</returns>
  48. protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
  49. {
  50. if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
  51. storage = value;
  52. RaisePropertyChanged(propertyName);
  53. return true;
  54. }
  55. /// <summary>
  56. /// Checks if a property already matches a desired value. Sets the property and
  57. /// notifies listeners only when necessary.
  58. /// </summary>
  59. /// <typeparam name="T">Type of the property.</typeparam>
  60. /// <param name="storage">Reference to a property with both getter and setter.</param>
  61. /// <param name="value">Desired value for the property.</param>
  62. /// <param name="propertyName">Name of the property used to notify listeners. This
  63. /// value is optional and can be provided automatically when invoked from compilers that
  64. /// support CallerMemberName.</param>
  65. /// <param name="onChanged">Action that is called after the property value has been changed.</param>
  66. /// <returns>True if the value was changed, false if the existing value matched the
  67. /// desired value.</returns>
  68. protected virtual bool SetProperty<T>(ref T storage, T value, Action onChanged, [CallerMemberName] string propertyName = null)
  69. {
  70. if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
  71. storage = value;
  72. onChanged?.Invoke();
  73. RaisePropertyChanged(propertyName);
  74. return true;
  75. }
  76. /// <summary>
  77. /// Raises this object's PropertyChanged event.
  78. /// </summary>
  79. /// <param name="propertyName">Name of the property used to notify listeners. This
  80. /// value is optional and can be provided automatically when invoked from compilers
  81. /// that support <see cref="CallerMemberNameAttribute"/>.</param>
  82. protected void RaisePropertyChanged([CallerMemberName] string propertyName = null)
  83. {
  84. OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
  85. }
  86. /// <summary>
  87. /// Raises this object's PropertyChanged event.
  88. /// </summary>
  89. /// <param name="args">The PropertyChangedEventArgs</param>
  90. protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
  91. {
  92. PropertyChanged?.Invoke(this, args);
  93. }
  94. #endregion
  95. }
  96. }