c# - Collection of objects shared in different viewmodels -


in wpf application i've collection of objects received via socket. collection composed of dictionary<int, imyobject> , it's periodically filled/updated when object received on socket. i've 4 different viewmodels gets subset of collection (i've myobjectholder static instance holding item , subset of doing as

public ilist<myobject> listtypeone {         {         mylist.where(x => x.type == mytype)     } } 

each time item inserted/updated, send notifyofpropertychanged on properties typeone typen.

is there better implementation don't see?

i've not heavily stress tested don't know how performs when i've large number of objects in collection.

i'm not sure if best solution, here's do.

  1. create static instance of collection (you've done already.)
  2. have service, or something periodically update collection (you've done already)
  3. push notifications viewmodels force them refresh bindings. (the tricky part)

now, there few ways can handle number 3. 1 of these ways use caliburn micro's event aggregator. can find out here.

essentially, allow viewmodels subscribe event. service, or whatever that's updating collection publish event, , subscribers called. pretty cool, right?

this allows keep viewmodels nice , decoupled, mvvm likes.

now, i'm not saying have cave in , install caliburn micro (i wouldn't blame if didn't). there's no reason why can't implement own event aggregator, heck, there's loads of tutorials , sample code can find if use right search terms.

personally, i'm not massive fan of using framework, feels dirty, that's down personal preference.

but anyway, give try , see works you.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -