Click or drag to resize

ModelBaseUpdateProperty Method (String, Action)

Informs a property that it should invoke its OnPropertyChanged event.

Namespace:  Xcalibur.Extensions.MVVM.Models
Assembly:  Xcalibur.Extensions.MVVM (in Xcalibur.Extensions.MVVM.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
public void UpdateProperty(
	string propertyName = null,
	Action onChanged = null
)

Parameters

propertyName (Optional)
Type: SystemString
Name of the property.
onChanged (Optional)
Type: SystemAction
The on changed.

Implements

INotifyUpdateProperty(String, Action)
Examples
C#
 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}
See Also