using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; namespace butterflow_ui { /// A class responsible for implementing the interface and helper functions. public abstract class PropertyChangedAlerter : INotifyPropertyChanged { #region Members /// Occurs when a property value changes. public event PropertyChangedEventHandler PropertyChanged; /// A list of properties to always call as updated. Generally used for composite properties. private List alwaysCall = new List(); #endregion #region Properties // #endregion #region Methods /// Executes the property changed action. /// The name. protected virtual void OnPropertyChanged([CallerMemberName]string name = null) { if (!string.IsNullOrWhiteSpace(name)) { this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); foreach (var updatedProperty in this.alwaysCall) { this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(updatedProperty)); } } } /// Adds a property that will always be called when any property is updated.. /// The name of the property. public void AddConstantCallProperty(string name) { if (!this.alwaysCall.Any(c => c.Equals(name, StringComparison.OrdinalIgnoreCase))) { this.alwaysCall.Add(name); } } #endregion } }