问题描述
我尝试使用以下实施ObservableDictionary的: ObservableDictionary(C#)。
I'm trying to use following implementation of the ObservableDictionary: ObservableDictionary (C#).
当我使用以下code,而该词典绑定到一个DataGrid:
When I'm using following code while binding the dictionary to a DataGrid:
ObserveableDictionary<string,string> dd=new ObserveableDictionary<string,string>();
....
dd["aa"]="bb";
....
dd["aa"]="cc";
在 DD [AA] =CC;
我收到以下异常
Index was out of range. Must be non-negative and less than the size of the
collection. Parameter name: index
这异常在抛出CollectionChanged(这一点,在下面的方法新的NotifyCollectionChangedEventArgs(行动的newitem,oldItem)
:
private void OnCollectionChanged(NotifyCollectionChangedAction action, KeyValuePair<TKey, TValue> newItem, KeyValuePair<TKey, TValue> oldItem)
{
OnPropertyChanged();
if (CollectionChanged != null) CollectionChanged(this, new NotifyCollectionChangedEventArgs(action, newItem, oldItem));
}
的首页
参数似乎对应 KeyValuePair&LT; TKEY的,TValue&GT; oldItem
。
哪有 KeyValuePair&LT; TKEY的,TValue&GT;
超出范围,和我应该怎么办,使这项工作。
How can KeyValuePair<TKey, TValue>
be out of range, and what should I do to make this work?
推荐答案
类似的数据结构,结合字典类型的集合
Similar data structure, to bind to Dictionary type collection
它提供了一个新的数据结构ObservableDictionary和火灾的任何变化底层词典时的PropertyChanged 。
It provides a new Data structure ObservableDictionary and fires PropertyChanged in case of any change to underlying Dictionary.
这篇关于ObservableDictionary的C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!