2

我有一个包含对象数组的数据网格,在我向错误集合添加错误 (IErrorInfo) 之前,一切都运行良好

在 Property Changed 发生以下错误

protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); <//---- here
            }
        }

和 DataGrid.UpdateLayout

    TimesheetArray = CreateMatrix(SelectedTimesheet.TimesheetDetails);
    RaisePropertyChanged("TimesheetArray");
    this.CrossTabDG.UpdateLayout();//----- HERE
    this.CrossTabDG.ItemsSource = this.TimesheetArray;

错误代码

System.ArgumentNullException occurred
  Message=Key cannot be null.
Parameter name: key
  Source=System
  ParamName=key
  StackTrace:
       at System.Collections.Specialized.HybridDictionary.get_Item(Object key)
       at System.ComponentModel.PropertyChangedEventManager.PrivateAddListener(INotifyPropertyChanged source, IWeakEventListener listener, String propertyName)
       at System.ComponentModel.PropertyChangedEventManager.AddListener(INotifyPropertyChanged source, IWeakEventListener listener, String propertyName)
       at MS.Internal.Data.PropertyPathWorker.ReplaceItem(Int32 k, Object newO, Object parent)
       at MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(Int32 k, ICollectionView collectionView, Object newValue, Boolean isASubPropertyChange)
       at MS.Internal.Data.ClrBindingWorker.AttachDataItem()
       at System.Windows.Data.BindingExpression.Activate(Object item)
       at System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt attempt)
       at System.Windows.Data.BindingExpression.AttachOverride(DependencyObject target, DependencyProperty dp)
       at System.Windows.Data.BindingExpressionBase.Attach(DependencyObject target, DependencyProperty dp)
       at System.Windows.Data.BindingExpressionBase.OnAttach(DependencyObject d, DependencyProperty dp)
       at System.Windows.StyleHelper.GetInstanceValue(UncommonField`1 dataField, DependencyObject container, FrameworkElement feChild, FrameworkContentElement fceChild, Int32 childIndex, DependencyProperty dp, Int32 i, EffectiveValueEntry& entry)
       at System.Windows.StyleHelper.GetChildValueHelper(UncommonField`1 dataField, ItemStructList`1& valueLookupList, DependencyProperty dp, DependencyObject container, FrameworkObject child, Int32 childIndex, Boolean styleLookup, EffectiveValueEntry& entry, ValueLookupType& sourceType, FrameworkElementFactory templateRoot)
       at System.Windows.StyleHelper.GetChildValue(UncommonField`1 dataField, DependencyObject container, Int32 childIndex, FrameworkObject child, DependencyProperty dp, FrugalStructList`1& childRecordFromChildIndex, EffectiveValueEntry& entry, ValueLookupType& sourceType, FrameworkElementFactory templateRoot)
       at System.Windows.StyleHelper.GetValueFromStyleOrTemplate(FrameworkObject fo, DependencyProperty dp, EffectiveValueEntry& entry)
       at System.Windows.FrameworkElement.GetRawValue(DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry& entry)
       at System.Windows.FrameworkElement.EvaluateBaseValueCore(DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry& newEntry)
       at System.Windows.DependencyObject.EvaluateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry newEntry, OperationType operationType)
       at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
       at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp)
       at System.Windows.StyleHelper.InvalidateDependents(Style ownerStyle, FrameworkTemplate frameworkTemplate, DependencyObject container, DependencyProperty dp, FrugalStructList`1& dependents, Boolean invalidateOnlyContainer)
       at System.Windows.StyleHelper.OnTriggerSourcePropertyInvalidated(Style ownerStyle, FrameworkTemplate frameworkTemplate, DependencyObject container, DependencyProperty dp, DependencyPropertyChangedEventArgs changedArgs, Boolean invalidateOnlyContainer, FrugalStructList`1& triggerSourceRecordFromChildIndex, FrugalMap& propertyTriggersWithActions, Int32 sourceChildIndex)
       at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
       at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
       at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
       at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
       at System.Windows.DependencyObject.SetValue(DependencyPropertyKey key, Object value)
       at System.Windows.Controls.Validation.AddValidationError(ValidationError validationError, DependencyObject targetElement, Boolean shouldRaiseEvent)
       at System.Windows.Data.BindingGroup.AddValidationError(ValidationError validationError)
       at System.Windows.Data.BindingGroup.ValidateOnDataTransfer()
       at System.Windows.Data.BindingGroup.OnLayoutUpdated(Object sender, EventArgs e)
       at System.Windows.ContextLayoutManager.fireLayoutUpdateEvent()
       at System.Windows.ContextLayoutManager.UpdateLayout()
       at System.Windows.UIElement.UpdateLayout()
       at TimesheetEntry.Views.TimesheetEntryViewModel.UpdateTimesheetGrid() in C:\Data Drive\Projects\DotNET\Laing_ORourke\source\TimesheetEntry\TimesheetEntry\Views\TimesheetEntry\TimesheetEntryViewModel.cs:line 405
  InnerException: 

谁能告诉我如何找到丢失的密钥

1) PropertyName 不为空 2) UpdateLayout() 不需要参数

没有 ValidationErrors - 没有问题 - 但我确实需要它,

4

2 回答 2

8

当您为 Binding 限定所有者类型并且您指定的类型不是它在运行时绑定的类型时,通常会发生这种情况。

例如:

<Setter Property="Canvas.Top" Value="{Binding (viewModels:FaceWithCandidates.Face).FaceRectangle.Top}" />

如果您正在限定绑定说您正在处理 FaceWithCandidates 并且在运行时,数据上下文包含任何其他类型,它将抛出这种异常。

当您符合您的属性时,请检查您的绑定!:)

于 2016-05-03T14:05:03.787 回答
1

我想你已经解决了这个问题或继续前进,但我会发布这个以供将来参考。


使用带有交替计数集的 ItemsControl 时,我遇到了同样的错误,我在 TextBlock 中显示。它只发生在一台特定的机器上,但是当我从 ItemContainerStyle 中删除下面的行时,异常消失了。

<TextBlock Text="{Binding (ItemsControl.AlternationIndex),
                          RelativeSource={RelativeSource Mode=TemplatedParent},
                          StringFormat='{}Item {0}'}"/>

所以看起来这个错误是由于一些错误的 XAML 代码而发生的。您可以尝试删除 controltemplate 样式并查看是否有效,如果有效,请添加元素直到再次出现错误,以便找出哪个元素不正确。似乎附加属性是罪魁祸首,所以我会先寻找那些。

于 2013-11-20T15:07:09.980 回答