У меня есть следующий код в моем приложении WPF, и я пытаюсь реализовать проверку ввода.
Модель:
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
}
ViewModel:
public class CustomerViewModel : Screen, IDataErrorInfo
{
private Customer _customer;
public Customer Customer
{
get { return _customer; }
set
{
if (_customer != value)
{
_customer = value;
NotifyOfPropertyChange(() => Customer);
}
}
}
public string Error
{
get
{
throw new NotImplementedException();
}
}
public string this[string columnName]
{
get
{
string result = null;
if (columnName == "Name")
{
if (string.IsNullOrEmpty(Customer.Name))
result = "Please enter a Name";
if (Customer.Name.Length < 3)
result = "Name is too short";
}
return result;
}
}
}
Вид:
<TextBox Text="{Binding Customer.Name, UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=true, NotifyOnValidationError=true}"/>
Проблема. Решение не работает должным образом. Ничего не происходит при вводе данных в текстовое поле. Я не уверен, что сделал правильные шаги.
Может ли кто-нибудь мне помочь?
UpdateSourceTrigger=PropertyChanged
? - person Mike Eason   schedule 04.11.2015