我曾经看到过ReactiveUI在过去有验证特性。目前,在6.5版中,我找不到任何与它相关的内容。
您知道在使用ReactiveUI的WPF中是否有多少官方的方法来处理验证任务吗?
发布于 2016-01-22 17:48:27
关于RxUI松弛组的总体共识是,人们正在公开额外的验证属性,例如拆分UserName和UserNameError (如果没有错误,则为null )。然后利用平台的验证/错误机制引起用户的注意。
发布于 2019-02-25 11:08:45
您不能看看这个回购https://github.com/reactiveui/ReactiveUI.Validation,也可以在NuGet画廊。
此解决方案基于MVVM模式,因此您的ViewModels必须实现ISupportsValidation、添加规则(ValidationHelper属性)并绑定到视图中的验证规则。
ViewModel
public class SampleViewModel : ReactiveObject, ISupportsValidation
{
public ValidationContext ValidationContext => new ValidationContext();
// Bindable rule
public ValidationHelper ComplexRule { get; set; }
public SampleViewModel()
{
// name must be at least 3 chars - the selector heee is the property name and its a single property validator
this.ValidationRule(vm => vm.Name, _isDefined, "You must specify a valid name");
}
}视图
public class MainActivity : ReactiveAppCompatActivity<SampleViewModel>
{
public EditText nameEdit { get; set; }
public TextInputLayout til { get; set; }
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our View from the "main" layout resource
SetContentView(Resource.Layout.Main);
WireUpControls();
// bind to an Android TextInputLayout control, utilising the Error property
this.BindValidation(ViewModel, vm => vm.ComplexRule, til);
}
}视图示例利用了DroidExtensions (为Mono.Droid项目自动添加),但是您可以将错误消息绑定到视图的任何控件。
希望能帮上忙。
诚挚的问候。
https://stackoverflow.com/questions/34952572
复制相似问题