views:

144

answers:

1

I have a bunch of ObservableCollections which are populated from a database. There's agood chance that during the application lifetime these collections will grow and i need them to be updated every 30 seconds or so.

I declare the collections as resources in merged dictionaries in App.xaml. I can fetch these collections fine by using the Application.FindResource() method but any changes I make to the resulting collection are not reflected when I call FindResource again. Maybe I'm naive to think this would be the case.

Am I right or wrong?

A: 

Got it!

a resources value can be set through Application.Current.Resources[key].

So in my example, should anyone run into this problem i do something like.

MyObservableCollection coll1 = Application.FindResource("resourceName") as MyObservableCollection
foreach(Item i in coll1)
{
    if(somecondition){i.someProperty == someValue;}
}
//coll2 does NOT reflect the above change!!!
MyObservableCollection coll2 = Application.FindResource("resourceName") as MyObservableCollection;
Application.Current.Resources["resourceName"] = coll1;
//coll3 DOES reflect the above change
MyObservableCollection coll3 = Application.FindResource("resourceName") as MyObservableCollection
Stimul8d