我有3个文本框,当它不满足特定条件时,我尝试添加验证提示。条件如下:
Disable submit button and show hints until textbox1 <= textbox2 and textbox3 >= 15% of textbox2
现在,我只能通过以下方法弄清楚如何检查长度或将其设为必需:
public class AttributeValidationViewModel : AnnotationValidationViewModel
{
private string _FirstName;
[Required(ErrorMessage = "# of containers is required")]
[MinLength(3,ErrorMessage = "textbox must have at least three characters")]
public string FirstName
{
get => _FirstName;
set => Set(ref _FirstName,value);
}
private string _LastName;
[Required]
public string LastName
{
get => _LastName;
set => Set(ref _LastName,value);
}
public RelayCommand SubmitCommand { get; }
public AttributeValidationViewModel()
{
SubmitCommand = new RelayCommand(OnSubmit,CanSubmit);
//Doing this will cause the errors to show immediately
ValidateModel();
}
private bool CanSubmit()
{
return !HasErrors;
}
private void OnSubmit()
{
Debug.WriteLine("Form Submittedffff");
}
我想添加类似的内容
[CustomCondition(ErrorMessage = "textbox must have at least three characters")] (like line 5 of the code)
我只是不知道该怎么做。我知道如何在有条件的情况下禁用该按钮,但是我也在尝试在文本框中提供验证提示。