2

オブジェクトの配列を含むデータグリッドがあります。エラーコレクションにエラー(IErrorInfo)を追加するまで、すべてが完全に正常に機能します。

プロパティ変更時に次のエラーが発生します

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がnullではない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

あなたはすでにこれを解決したか、先に進んだと思いますが、今後の参考のために投稿します。


TextBlock に表示した代替カウント セットを含む ItemsControl を使用すると、同じエラーが発生しました。特定のマシンでのみ発生しましたが、ItemContainerStyle から以下の行を削除すると、例外は消えました。

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

そのため、このエラーは XAML コードの不具合が原因で発生しているようです。controltemplate スタイルを削除して、それが機能するかどうかを確認し、機能する場合は、エラーが再び発生するまで要素を追加して、どの要素が正しくないかを調べることができます。ただし、添付プロパティが原因のようですので、最初にそれらを探します。

于 2013-11-20T15:07:09.980 に答える