 | 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
Syntaxprotected 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
)
Protected Overridable Function TrySetValueSilent(Of TValue) (
value As TValue,
validationDelegate As Func(Of TValue, (IsValid As Boolean, ErrorMessages As IEnumerable(Of String))),
ByRef targetBackingField As TValue,
Optional isRejectInvalidValueEnabled As Boolean = false,
Optional isThrowExceptionOnValidationErrorEnabled As Boolean = false,
Optional propertyName As String = Nothing
) As Boolean
Dim value As TValue
Dim validationDelegate As Func(Of TValue, (IsValid As Boolean, ErrorMessages As IEnumerable(Of String)))
Dim targetBackingField As TValue
Dim isRejectInvalidValueEnabled As Boolean
Dim isThrowExceptionOnValidationErrorEnabled As Boolean
Dim propertyName As String
Dim returnValue As Boolean
returnValue = Me.TrySetValueSilent(value,
validationDelegate, targetBackingField,
isRejectInvalidValueEnabled, isThrowExceptionOnValidationErrorEnabled,
propertyName)
protected:
generic<typename TValue>
virtual bool TrySetValueSilent(
TValue value,
Func<TValue, ValueTuple<bool, IEnumerable<String^>^>>^ validationDelegate,
TValue% targetBackingField,
bool isRejectInvalidValueEnabled = false,
bool isThrowExceptionOnValidationErrorEnabled = false,
String^ propertyName = nullptr
)
abstract TrySetValueSilent :
value : 'TValue *
validationDelegate : Func<'TValue, ValueTuple<bool, IEnumerable<string>>> *
targetBackingField : 'TValue byref *
?isRejectInvalidValueEnabled : bool *
?isThrowExceptionOnValidationErrorEnabled : bool *
?propertyName : string
(* Defaults:
let _isRejectInvalidValueEnabled = defaultArg isRejectInvalidValueEnabled false
let _isThrowExceptionOnValidationErrorEnabled = defaultArg isThrowExceptionOnValidationErrorEnabled false
let _propertyName = defaultArg propertyName null
*)
-> bool
override TrySetValueSilent :
value : 'TValue *
validationDelegate : Func<'TValue, ValueTuple<bool, IEnumerable<string>>> *
targetBackingField : 'TValue byref *
?isRejectInvalidValueEnabled : bool *
?isThrowExceptionOnValidationErrorEnabled : bool *
?propertyName : string
(* Defaults:
let _isRejectInvalidValueEnabled = defaultArg isRejectInvalidValueEnabled false
let _isThrowExceptionOnValidationErrorEnabled = defaultArg isThrowExceptionOnValidationErrorEnabled false
let _propertyName = defaultArg propertyName null
*)
-> bool
J# supports the use of generic APIs, but not the declaration of new ones.
JScript does not support generic types or methods.
JavaScript does not support generic types or methods.
PROTECTED VIRTUAL METHOD TrySetValueSilent<TValue>(
value AS TValue,
validationDelegate AS Func<TValue, ValueTuple<LOGIC, IEnumerable<STRING>>>,
targetBackingField REF TValue,
isRejectInvalidValueEnabled AS LOGIC := FALSE,
isThrowExceptionOnValidationErrorEnabled AS LOGIC := FALSE,
propertyName AS STRING := NULL
)
AS LOGIC
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:
BooleanReturns
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
RemarksThis 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