【发布时间】:2016-03-23 11:27:40
【问题描述】:
我有一个包含年龄的 TextBox 表单。我已经实现了这样的验证:
在我的 ViewModel 中,我有财产年龄:
private float age;
public float Age {
get { return age; }
set
{
if (value <= 0 || value > 120)
{
throw new ArgumentException("The age must be between 0 and 120 years");
}
age= value;
}
}
我的 XAML 是:
<TextBox Name="txtAge" Text="{Binding Age, UpdateSourceTrigger=PropertyChanged, StringFormat=N1, ValidatesOnExceptions=True}" />
这一切都很好,如果我输入年龄 300,我的文本框下会显示错误。但是如果发生错误,我该如何禁用按钮呢?
【问题讨论】: