У меня есть idataerrorinfo, как показано ниже, но он не работает. Можете ли вы мне помочь? Это не ошибка на экране при отладке.idataerrorinfo в C# WPF
Модель часть:
class Person : Viewmodelbase, INotifyPropertyChanged{
private string name;
private string age;
public string Name{
get
{
return name;
}
set
{
name = value;
if (string.IsNullOrWhiteSpace(value))
{
this.seterror("Name", "Please Input sth");
}
else
clearerror("Name");
OnpropertyChanged("name");
}
}
}
Viewmodelbase часть:
class Viewmodelbase : INotifyPropertyChanged, IDataErrorInfo
{
public event PropertyChangedEventHandler PropertyChanged;
public void onpropertychange(string property)
{
if (string.IsNullOrEmpty(property))
PropertyChanged(this, new PropertyChangedEventArgs(property));
}
string IDataErrorInfo.Error
{
get
{
throw new NotImplementedException();
}
}
private Dictionary<string, string> error1 = new Dictionary<string, string>();
public string this[string columnName]
{
get
{
if (error1.ContainsKey(columnName))
return error1[columnName];
return null;
}
}
public void seterror(string key1,string value1)
{
this.error1[key1] = value1;
this.onpropertychange("HasError");
}
public void clearerror(string key1)
{
if (this.error1.ContainsKey(key1))
{
this.error1.Remove(key1);
this.onpropertychange("HasError");
}
}
protected void ClearErrors()
{
this.error1.Clear();
this.onpropertychange("HasError");
}
public bool HasError
{
get
{
return this.error1.Count != 0;
}
}
}
модели представления часть:
class MainWindowViewModel : Viewmodelbase,INotifyPropertyChanged
{
public Person myboy
{
get;
set;
}
}
WPF часть:
<TextBox Width="250" FontSize="20" VerticalAlignment="Center" DataContext="{Binding Source={StaticResource VM}}" Text="{Binding Path=myboy.Name,Mode=TwoWay,ValidatesOnDataErrors=True,UpdateSourceTrigger=PropertyChanged,NotifyOnValidationError=True,ValidatesOnExceptions=True}" Name="textbox1" Margin="0,199"></TextBox>
'певд NotImplementedException();' все facepalms. – Will