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
I'm trying the samples adapted to a WPF project.
I copied the ViewModel sample as-is and created a WPF view with type-safe bindings like the given android sample.
ViewModel:
publicclassSampleViewModel:ReactiveObject,ISupportsValidation{publicSampleViewModel(){// Name must be at least 3 chars. The selector is the property name and the line below is// a single property validator.this.ValidationRule(viewModel => viewModel.Name,name =>!string.IsNullOrWhiteSpace(name),"You must specify a valid name");// Age must be between 13 and 100, message includes the silly length being passed in,// stored in a property of the ViewModel.AgeRule=this.ValidationRule(viewModel => viewModel.Age,age =>age >= 13&&age <= 100,age =>$"{age} is a silly age");varnameAndAgeValid=this.WhenAnyValue(x => x.Age,x => x.Name,(age,name)=>new{ Age = age, Name = name }).Select(x => x.Age >10&&!string.IsNullOrEmpty(x.Name));// Create a rule from an IObservable.ComplexRule=this.ValidationRule(_ => nameAndAgeValid,(vm,state)=>!state?"That's a ridiculous name / age combination":string.Empty);// IsValid extension method returns true when all validations succeed.varcanSave=this.IsValid();// Save command is only active when all validators are valid.Save= ReactiveCommand.CreateFromTask(async unit =>{}, canSave);}[Reactive]publicintAge{get;set;}// Declare a separate validator for age rule.publicValidationHelperAgeRule{get;}// Declare a separate validator for complex rule.publicValidationHelperComplexRule{get;}[Reactive]publicstringName{get;set;}publicReactiveCommand<Unit,Unit> Save {get;}// Initialize validation context that manages reactive validations.publicValidationContextValidationContext{get;}=new ValidationContext();}
publicpartialclassMainWindow{publicMainWindow(){
InitializeComponent();this.WhenActivated(disposables =>{this.Bind(ViewModel,vm => vm.Name,view => view.NameTextBox.Text);// This works finethis.BindValidation(ViewModel,view => view.ErrorsTextBlock.Text);// This fails with a NullReferenceExceptionthis.BindValidation(ViewModel,vm => vm.Name,view => view.ErrorsTextBlock.Text);});}}
I'm using the latest stable version of ReactiveUI 9.12.1 and the latest validation version 1.0.3:
Also with the one that works, every validation message is appended to each other without a NewLine or anything. How do I customize this? I can open another issue if needed.
The text was updated successfully, but these errors were encountered:
Everything seems fine, so I would need to reproduce it in my machine. The problem is that I don't have a Windows, so I will have to create a virtual machine and then set everything up. I hope to give you some feedback over the weekend.
The problem is with reflection resolve naming. If you register the validation with "viewModel" instead of "vm" in the lambda expression or by changing the ViewModel validation with the "vm" instead of "viewModel". This workaround works fine.
See the screenshots below:
I will find the solution soon to fix this. And thank you so much for reporting this bug.
I'm trying the samples adapted to a WPF project.
I copied the ViewModel sample as-is and created a WPF view with type-safe bindings like the given android sample.
ViewModel:
View:
I'm using the latest stable version of ReactiveUI 9.12.1 and the latest validation version 1.0.3:
Also with the one that works, every validation message is appended to each other without a NewLine or anything. How do I customize this? I can open another issue if needed.
![Capture](https://user-images.githubusercontent.com/15314924/55150465-77283980-514c-11e9-9391-bc6fa862233a.PNG)
The text was updated successfully, but these errors were encountered: