Click or drag to resize

ViewModel.TrySetValueSilent<TValue> Method (TValue, Func<TValue, ValueTuple<Boolean, IEnumerable<String>>>, TValue, Boolean, Boolean, String)

Silently sets the value of the referenced property without raising PropertyChanged and executes a validation delegate.

Namespace:  BionicCode.Utilities.Net.Standard.ViewModel
Assembly:  BionicCode.Utilities.Net.Standard (in BionicCode.Utilities.Net.Standard.dll) Version: 1.0.4
Syntax
protected virtual bool TrySetValueSilent<TValue>(
	TValue value,
	Func<TValue, (bool IsValid, IEnumerable<string> ErrorMessages)> validationDelegate,
	ref TValue targetBackingField,
	bool isRejectInvalidValueEnabled = false,
	bool isThrowExceptionOnValidationErrorEnabled = false,
	string propertyName = null
)

Parameters

value
Type: TValue
The new value which is to be set to the property.
validationDelegate
Type: System.Func<TValue, ValueTuple<Boolean, IEnumerable<String>>>
The callback that is used to validate the new value.
targetBackingField
Type: TValue
The reference to the backing field.
isRejectInvalidValueEnabled (Optional)
Type: System.Boolean
When true the invalid value is not stored to the backing field.
Use this to ensure that the view model in a valid state.
isThrowExceptionOnValidationErrorEnabled (Optional)
Type: System.Boolean
Enable throwing an if validation failed. Use this when ValidatesOnExceptions on a Binding is set to true
propertyName (Optional)
Type: System.String
The name of the property to set. Default name is the property that called this method.

Type Parameters

TValue
The generic value type parameter

Return Value

Type: Boolean
Returns true if the new value doesn't equal the old value and the new value is valid. Returns false if the new value equals the old value or the validation has failed.
Exceptions
ExceptionCondition
ArgumentExceptionThrown on validation failed
Remarks
This property setter supports invalid value rejection, which means values are only assigned to the backing field if they are valid which is when the validationDelegate return true.
To support visual validation error feed back and proper behavior in TwoWay binding scenarios,
it is recommended to set isThrowExceptionOnValidationErrorEnabled to true and set the validation mode of the binding to Binding.ValidatesOnExceptions.
If not doing so, the binding target will clear the new value and show the last valid value instead.
See Also
https://github.com/BionicCode/BionicCode.Net/blob/master/README.md