아래와 같이 idataerrorinfo를 구현했지만 작동하지 않는다면 모두 도와 줄 수 있습니까? 디버깅 할 때 화면에 오류가 나타나지 않습니다.idataerrorinfo in 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 던져() : 나는 당신과 같은 코드를 게시 할 경우 질문에 대한 답을 귀찮게하지 않습니다 다음에) 여기
당신을위한 영감이다. – Will