Skip to content

[Feature] Allow ObservableValidator to force re-evaluation of validation for a property  #3742

@pixsperdavid

Description

@pixsperdavid

Describe the problem this feature would solve

I have a simple, common situation which is very hard to resolve with the current ObservableValidator implementation. I have a set of number boxes setting TCP port values for various services. Their validation rule is set to ensure that the value of each must be unique (cannot be the same as any other value). Due to this, it is possible that a value which failed validation due to not being unique, could then become valid as the result of another value changing. Therefore upon any value in the set changing, the validation rules for all values must be re-evaulated. However, ObservableValidator currently offers no way to force re-evaluate the validation of a property unless it's value changes.

Describe the solution

Add a 'RevalidateProperty' method to ObservableValidator. This simply invokes the existing private 'ValidateProperty' method. I have currently done this in my project and the solution works well, albeit I have to call the method via reflection. The new method would be used as follows:

public int ExampleValue1
{
    get => _exampleValue1;
    set
    {
        if (SetProperty(ref _exampleValue1, value, true))
            RevalidateProperty(ExampleValue2, nameof(ExampleValue2));
    }
}

Describe alternatives you've considered

A possible alternative is to change the value of the property requiring re-validation to a temporary value and then change it back to the original value, however this feels very hacky and doesn't accurately express the intention. It also has the possibility of triggering unintentional/undesirable side-effects as it would not be a 'real' value change.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions