【发布时间】:2011-09-16 02:00:07
【问题描述】:
我在屏幕上有 2 个文本框,一个是“从金额”,另一个是“到金额”。验证规则是 'from amount' 应该小于 'to amount'。
现在我的问题是,当用户输入一对“从金额”大于“到金额”的金额时, 如何使两个文本框都显示为红色边框。当用户更正金额时(无论是 通过减少 'from amount' 或增加 'to amount' ,如何使两个文本框都显示 出现错误?
谢谢
我的代码如下所示:
public partial class Rate : IDataErrorInfo
{
public Rate()
{
is_active = true;
registered = DateTime.Now;
}
#region FOR validation
public string Error
{
get
{
var properties = this.GetType().GetProperties();
foreach (var propertyInfo in properties)
{
string err = this[propertyInfo.Name];
if (!string.IsNullOrEmpty(err))
{
return err;
}
}
return string.Empty;
}
}
public string this[string propertyName]
{
get
{
string result = null;
if (result == null && "from_amt" == propertyName)
{
if (from_amt > to_amt)
{
result = Resources.Validation.Rate_from_amount_value;
}
}
if (result == null && "to_amt" == propertyName)
{
if (from_amt > to_amt)
{
result = Resources.Validation.Rate_to_amount_value;
}
}
return result;
}
}
#endregion
}
}
【问题讨论】:
标签: wpf validation binding