我在WPF 4.5项目中做了一个简单的INotifyDataErrorInfo实现.这是WPF的新界面,但已在Silverlight中使用了一段时间.
我知道NET4.5仍然被认为是alpha,但我正在尝试解决它是我的代码还是错误的框架.
接口按预期工作,但是当对象绑定到DataGrid时失败.
我收到的例外是:
用户代码未处理System.NullReferenceException
消息=未将对象引用设置为对象的实例.
源= PresentationFramework堆栈跟踪:在MS.Internal.Data.ClrBindingWorker.OnDataErrorsChanged(INotifyDataErrorInfo indei,字符串PROPNAME)在MS.Internal.Data.PropertyPathWorker.OnErrorsChanged(对象发件人,DataErrorsChangedEventArgs e)上System.Windows.WeakEventManager.ListenerList`1.位于System.ComponentModel.ErrorsChangedEventManager.OnErrorsChanged(Object sender,DataErrorsChangedEventArgs args)的System.Windows.WeakEventManager.DeliverEvent(Object sender,EventArgs args)中的DeliverEvent(Object sender,EventArgs e,Type managerType)INotifyDataErrorInfoTest.Person.NotifyErrorsChanged(String property) )在INotifyDataErrorInfoTest\Person.cs:线109在INotifyDataErrorInfoTest.Person.AddErrorForProperty(String属性,字符串误差)INotifyDataErrorInfoTest\Person.cs:管线122 INotifyDataErrorInfoTest.Person.Validate(字符串propertyName的)在INotifyDataErrorInfoTest\Person.cs:线INotifyDataErrorInfoTest中的INotifyDataErrorInfoTest.Person.set_FirstName(String value)中的150\Person.cs:第18行
代码位于http://dl.dropbox.com/u/14740106/INotifyDataErrorInfoTest.zip下方或项目中
如果共识是这是一个错误,那么我将发布到MS Connect.
测试:有两个文本框绑定到Person对象的单个实例.将第一个文本框设置为具有值的James,它将无法通过验证并显示红色框.如果将网格中任何用户的名字设置为James,则会抛出异常.
PS:我知道它不是MVVM,但它只是为了证明或反驳问题.
public class Person : INotifyDataErrorInfo, INotifyPropertyChanged
{
string _firstName;
public string FirstName
{
get { return _firstName; }
set
{
_firstName = value;
Validate("FirstName");
OnPropertyChanged("FirstName");
}
}
string _lastName;
public string LastName
{
get { return _lastName; }
set
{
_lastName = value;
Validate("LastName");
OnPropertyChanged("LastName");
}
}
public Person()
{
} …Run Code Online (Sandbox Code Playgroud)