我的应用程序使用 WPF DataGrid
。其中一列是一个模板列,它包含一个ComboBox
绑定到ObservableCollection
提供该行的实体的一个。当我向 中添加值时ObservableCollection
,NullReferenceException
会抛出 a 。
有人知道为什么会这样吗?这是异常的堆栈跟踪:
在 MS.Internal.Data.PropertyPathWorker.DetermineWhetherDBNullIsValid() 在 MS.Internal.Data.PropertyPathWorker.get_IsDBNullValidForUpdate() 在 MS.Internal.Data.ClrBindingWorker.get_IsDBNullValidForUpdate() 在 System.Windows.Data.BindingExpression.ConvertProposedValue(对象值) 在 System.Windows.Data.BindingExpressionBase.UpdateValue() 在 System.Windows.Data.BindingExpression.Update(布尔同步) 在 System.Windows.Data.BindingExpressionBase.Dirty() 在 System.Windows.Data.BindingExpression.SetValue(DependencyObject d,DependencyProperty dp,对象值) 在 System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp、对象值、PropertyMetadata 元数据、布尔 coerceWithDeferredReference、OperationType operationType、布尔 isInternal) 在 System.Windows.DependencyObject.SetValue(DependencyProperty dp,对象值) 在 System.Windows.Controls.Primitives.Selector.UpdatePublicSelectionProperties() 在 System.Windows.Controls.Primitives.Selector.SelectionChanger.End() 在 System.Windows.Controls.Primitives.Selector.OnItemsChanged(NotifyCollectionChangedEventArgs e) 在 System.Windows.Controls.ItemsControl.OnItemCollectionChanged(对象发送者,NotifyCollectionChangedEventArgs e) 在 System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(对象发送者,NotifyCollectionChangedEventArgs e) 在 System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs 参数) 在 System.Windows.Controls.ItemCollection.System.Windows.IWeakEventListener.ReceiveWeakEvent(类型 managerType,对象发送者,EventArgs e) 在 System.Windows.WeakEventManager.DeliverEventToList(对象发送者,EventArgs 参数,ListenerList 列表) 在 System.Windows.WeakEventManager.DeliverEvent(对象发送者,EventArgs 参数) 在 System.Collections.Specialized.CollectionChangedEventManager.OnCollectionChanged(对象发送者,NotifyCollectionChangedEventArgs 参数) 在 System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs 参数) 在 System.Windows.Data.ListCollectionView.ProcessCollectionChangedWithAdjustedIndex(NotifyCollectionChangedEventArgs 参数,Int32 调整的OldIndex,Int32 调整的NewIndex) 在 System.Windows.Data.ListCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs 参数) 在 System.Windows.Data.CollectionView.OnCollectionChanged(对象发送者,NotifyCollectionChangedEventArgs 参数) 在 System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e) 在 System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 索引,T 项) 在 System.Collections.ObjectModel.Collection`1.Add(T 项) 在 ORF.PersonBook.IdentityModule.Model.SubsidiaryModel.AddRoom(RoomModel room) 在 C:\Project\Phoenix\Development\src\ORF.PersonBook.IdentityModule\Model\SubsidiaryModel.cs:line 127