ModelBaseUpdateProperty Method (String, Action) |
Namespace: Xcalibur.Extensions.MVVM.Models
1/// <summary> 2/// Updates a property directly by comparing values and then firing its 3/// OnPropertyChanged event if necessary. 4/// </summary> 5/// <typeparam name="T"></typeparam> 6/// <param name="propertyName">Name of the property.</param> 7/// <param name="newValue">The new value.</param> 8/// <param name="valueReference">The value reference.</param> 9/// <param name="onChanged">The on changed.</param> 10public void NotifyOfChange<T>(string propertyName, T newValue, 11 ref T valueReference, Action onChanged = null) 12{ 13 if (!Equals(newValue, null)) 14 { 15 // If values are the same, exit 16 if (newValue.Equals(valueReference)) return; 17 18 // Assign new value 19 valueReference = newValue; 20 } 21 else 22 { 23 valueReference = default(T); 24 } 25 26 // Fire OnPropertyChanged 27 UpdateProperty(propertyName, onChanged); 28}