Click or drag to resize

ModelBaseExtensionsUpdatePropertyT Method

Informs a property that it should invoke its OnPropertyChanged event.

Namespace:  Xcalibur.Extensions.MVVM.Extensions
Assembly:  Xcalibur.Extensions.MVVM (in Xcalibur.Extensions.MVVM.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
public static void UpdateProperty<T>(
	this T model,
	Expression<Func<T, Object>> property,
	Action onChanged = null
)
where T : INotify

Parameters

model
Type: T
The model.
property
Type: System.Linq.ExpressionsExpressionFuncT, Object
The property.
onChanged (Optional)
Type: SystemAction
The on changed.

Type Parameters

T

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type . When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
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