Search code examples
c#validation.net-corexamarin.formsreactiveui

How to manually re-validate the Validations of the ValidationContext in ReactiveUI?


I need to force the ValidationContext to re-validate its Validations / ValidationRules when a specific property of my ViewModel changes. I don't see any methods to trigger validation, e.g. a Validate() method. I'm using ReactiveUI.Validation framework.


Solution

  • This is the code that calls the IsValid delegate in ReactiveUI. This code can be found in class BasePropertyValidation.

        protected override IObservable<IValidationState> GetValidationChangeObservable()
        {
            Activate();
            return _valueSubject
                .Select(value => new ValidationState(_isValidFunc(value), _message(value, _isValidFunc(value))))
                .DistinctUntilChanged(new ValidationStateComparer());
        }
    

    And this code is ONLY triggered on a change of the validated property value.

    So the answer is: ReactiveUI.Validation does not provide functionality to trigger any validation without changing property values.