【发布时间】:2014-10-01 19:20:46
【问题描述】:
我创建了一个很少有自定义验证的模型。这些自定义验证我已通过以下代码在属性处进行了注释
[CustomValidation(typeof(ItemmasterModel), "ValueTextMaxLenghtValidate")]
public decimal Valuetextmaxlength
{
get
{
return _Valuetextmaxlength;
}
set
{
ValidateProperty("Valuetextmaxlength",value);
_Valuetextmaxlength = value;
RaisePropertyChanged(() => Valuetextmaxlength);
}
}
public static ValidationResult ValueTextMaxLenghtValidate(object obj, ValidationContext context)
{
var itmmstr = (ItemmasterModel)context.ObjectInstance;
if (itmmstr.SelectedValuetypeDd != null)
{
string vtype = itmmstr.SelectedValuetypeDd.Key.ToString();
if (vtype.Equals("C"))
{
if (itmmstr.SelectedItemValueCodeTypesDd != null)
{
string vcode = itmmstr.SelectedItemValueCodeTypesDd.Key.ToString();
if (vcode.Equals("T"))
{
if (itmmstr.Valuetextmaxlength == null || itmmstr.Valuetextmaxlength == 0)
{
return new ValidationResult("Value Max Length is not Entered",
new List<string> { "Valuetextmaxlength" });
}
}
}
}
else if (vtype.Equals("T"))
{
if (itmmstr.Valuetextmaxlength == null || itmmstr.Valuetextmaxlength == 0)
{
return new ValidationResult("Value Max Length is not Entered",
new List<string> { "Valuetextmaxlength" });
}
}
}
return ValidationResult.Success;
}
现在这个验证码依赖于其他属性。场景当用户从下拉列表中选择一个值时,它会自动选中 1 个复选框,并且用户也应该在 texbox 中输入该值。
问题:
验证正在运行。第一次选中复选框,然后它还带有错误弹出窗口。 直到用户没有对此复选框或 texbox 进行更改,它只是有错误。 1 次说错误,甚至输入了值。下一次,即使用户没有输入任何内容,但在最终的完整对象验证期间再次出现错误。
为什么会出现这种模棱两可的情况。如何解决这个问题。 需要更多代码让我知道。我会发帖的。代码在 Silverlight 5,MVVM Light 中
【问题讨论】: