You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello there!
A question regarding usage of the validation package, in the context of a winforms project. For context, suppose I want to integrate with the ErrorProvider component. Since there isn't a way to bind the error messages directly to it, as the provider only exposes a function to set the error on the control, my best bet was to create an observable of all IPropertyValidationComponents, because it's the only object, reachable from the view, which has both the error messages and the property names that I could find.
My current iteration looks like this, in similar fashion to what I saw in ReactiveValidationObject's ctor:
//My best take at getting the list of validation errors out of the ValidationContext, so far. //It seems messy, but I took the idea directly from ReactiveValidationObject's ctor, so...varpropVals=this.ViewModel?.ValidationContext.Validations.ToObservableChangeSet().ToCollection().Select(
comps =>comps.Select(
comp =>comp.ValidationStatusChange.Select(_ =>comp)).Merge()//Merge instead of Switch, as in the reference ctor. .StartWith(this.ViewModel.ValidationContext)).Merge().Where(comp =>compisIPropertyValidationComponent).Cast<IPropertyValidationComponent>();
This works, but raises some questions, as follows:
Is there a better way to generate such observable, or even better, has it already been created somewhere, reachable from the view?
The fields are already being validated at form creation. Is there a way to start such observable in a pseudo valid state, so that at form opening I don't bombard my user with errors before he even tries to do something, but at the same time a command that depends on said validation is not enabled? I can take care of this last requirement, by adding the mandatory properties as part of the canExecute lambda for the command, together with the IsValid property of the context, but that is order dependent on the view model constructor, which is very error prone I think.
And how about adding a delay to the validation call? From what I can see, it's monitoring the change notifications immediately.
On the same vein, is it possible to also monitor focus changed on the control in question? This would be a must...
And last, but not least, since one of the properties has more than one validation rule, how can I get a single string with all the errors associated with it, to pass to the provider? My current solution, which uses the Text.ToSingleLine function on the IPropertyValidationComponent is showing only the last error.
I made a sample repository which demonstrates these questions right here
Any help is appreciated! And thanks for the library, it has been wonderful so far!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello there!
A question regarding usage of the validation package, in the context of a winforms project. For context, suppose I want to integrate with the ErrorProvider component. Since there isn't a way to bind the error messages directly to it, as the provider only exposes a function to set the error on the control, my best bet was to create an observable of all IPropertyValidationComponents, because it's the only object, reachable from the view, which has both the error messages and the property names that I could find.
My current iteration looks like this, in similar fashion to what I saw in ReactiveValidationObject's ctor:
This works, but raises some questions, as follows:
I made a sample repository which demonstrates these questions right here
Any help is appreciated! And thanks for the library, it has been wonderful so far!
Beta Was this translation helpful? Give feedback.
All reactions