0

I got a "well-constituted" ObservableCollection and I'd like to inspect into it. The definition of it is :

private Dictionary<string, ObservableCollection<DependencyObject>> _DataPools = new Dictionary<string, ObservableCollection<DependencyObject>>();

(yep it's an obsCol with an obsCol in it, but it IS ok, the problem's not here)

I tried 2 different ways but they both don't work...

1) .Items

foreach(ObservableCollection<DependencyObject> obj in _DataPools.Items)
        {
            blablaaaa;
            ....
        }

.Items doesn't work but when I look in the C#doc, Items is a valid field... (just like "Count", and "Count" works...)

2) Count + [x] acces :

var nbItems = _DataPools.Count;

        for (int i = 0; i < nbItems; i++)
        {
            Console.WriteLine("Items : " + _DataPools[i].XXX); //XXX = ranom method
        }

_DataPools[i] doesn't work but on the web I found a couple of example where it is used oO

I tried a couple of other "exotic" things but I really can't go over it...

Any help will be welcomed !

Thx in advance and sry for my langage, im french -_- (sry for my president too !)

Guillaume Slashy
  • 3,554
  • 8
  • 43
  • 68

4 Answers4

1

_DataPools is a dictionary, not an ObservableCollection.
You need to loop over .Values.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
0

_DataPool is not an observable collection in an observable collection. It's a dictionary that contains observable collections. To get the collections from the dictionary, use the Values property:

foreach (ObservableCollection<DependencyObject> obj in _DataPools.Values)
{
    // some code
}
svick
  • 236,525
  • 50
  • 385
  • 514
0

_DataPools is of type Dictionary. you can access the elements of a dictionary with Values property.

foreach(ObservableCollection<DependencyObject> obj in _DataPools.Values)
tafa
  • 7,146
  • 3
  • 36
  • 40
0

You are using a Dictionary, therefore you should use the property Keys to loop on keys and Values to loop on your items. This should work:

foreach(ObservableCollection<DependencyObject> obj in _DataPools.Values)
{
    blablaaaa;
    ....
}
Ucodia
  • 7,410
  • 11
  • 47
  • 81