SingleActionParam.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Runtime.CompilerServices;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace Team.FFFeederService.Models
  9. {
  10. /// <summary>
  11. /// 单个平台振动动作参数
  12. /// </summary>
  13. public class SingleActionParam : INotifyPropertyChanged
  14. {
  15. private VoiceMotorParam _Motor1;
  16. public VoiceMotorParam Motor1
  17. {
  18. get { return _Motor1; }
  19. set { SetProperty(ref _Motor1, value); }
  20. }
  21. private VoiceMotorParam _Motor2;
  22. public VoiceMotorParam Motor2
  23. {
  24. get { return _Motor2; }
  25. set { SetProperty(ref _Motor2, value); }
  26. }
  27. private VoiceMotorParam _Motor3;
  28. public VoiceMotorParam Motor3
  29. {
  30. get { return _Motor3; }
  31. set { SetProperty(ref _Motor3, value); }
  32. }
  33. private VoiceMotorParam _Motor4;
  34. public VoiceMotorParam Motor4
  35. {
  36. get { return _Motor4; }
  37. set { SetProperty(ref _Motor4, value); }
  38. }
  39. private int _DurationValue;
  40. /// <summary>
  41. /// 持续时长
  42. /// </summary>
  43. public int DurationValue
  44. {
  45. get { return _DurationValue; }
  46. set { SetProperty(ref _DurationValue, value); }
  47. }
  48. #region 属性更改通知
  49. /// <summary>
  50. /// Occurs when a property value changes.
  51. /// </summary>
  52. public event PropertyChangedEventHandler PropertyChanged;
  53. /// <summary>
  54. /// Checks if a property already matches a desired value. Sets the property and
  55. /// notifies listeners only when necessary.
  56. /// </summary>
  57. /// <typeparam name="T">Type of the property.</typeparam>
  58. /// <param name="storage">Reference to a property with both getter and setter.</param>
  59. /// <param name="value">Desired value for the property.</param>
  60. /// <param name="propertyName">Name of the property used to notify listeners. This
  61. /// value is optional and can be provided automatically when invoked from compilers that
  62. /// support CallerMemberName.</param>
  63. /// <returns>True if the value was changed, false if the existing value matched the
  64. /// desired value.</returns>
  65. protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
  66. {
  67. if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
  68. storage = value;
  69. RaisePropertyChanged(propertyName);
  70. return true;
  71. }
  72. /// <summary>
  73. /// Checks if a property already matches a desired value. Sets the property and
  74. /// notifies listeners only when necessary.
  75. /// </summary>
  76. /// <typeparam name="T">Type of the property.</typeparam>
  77. /// <param name="storage">Reference to a property with both getter and setter.</param>
  78. /// <param name="value">Desired value for the property.</param>
  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 that
  81. /// support CallerMemberName.</param>
  82. /// <param name="onChanged">Action that is called after the property value has been changed.</param>
  83. /// <returns>True if the value was changed, false if the existing value matched the
  84. /// desired value.</returns>
  85. protected virtual bool SetProperty<T>(ref T storage, T value, Action onChanged, [CallerMemberName] string propertyName = null)
  86. {
  87. if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
  88. storage = value;
  89. onChanged?.Invoke();
  90. RaisePropertyChanged(propertyName);
  91. return true;
  92. }
  93. /// <summary>
  94. /// Raises this object's PropertyChanged event.
  95. /// </summary>
  96. /// <param name="propertyName">Name of the property used to notify listeners. This
  97. /// value is optional and can be provided automatically when invoked from compilers
  98. /// that support <see cref="CallerMemberNameAttribute"/>.</param>
  99. protected void RaisePropertyChanged([CallerMemberName] string propertyName = null)
  100. {
  101. OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
  102. }
  103. /// <summary>
  104. /// Raises this object's PropertyChanged event.
  105. /// </summary>
  106. /// <param name="args">The PropertyChangedEventArgs</param>
  107. protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
  108. {
  109. PropertyChanged?.Invoke(this, args);
  110. }
  111. #endregion
  112. }
  113. }