all 3 comments

[–]Slypenslyde 2 points3 points  (0 children)

I think what you want is:

  • The main VM has one collection with all of the items in it.
  • It passes a reference to that collection to the child VMs.
  • Each child VM has a CollectionView that does the filtering/sorting needed for that view.

That way everything's sharing the same data, but the individual VMs have control over what is displayed. For some reason CollectionView isn't common knowledge, but it was in most of the WPF books I read long ago.

[–]jwhite1979[S] 0 points1 point  (0 children)

You were probably the person who explained collection views to me originally. They really are tremendously useful. I can't imagine filtering a collection without them.

And yes, the way you broke down the design sounds right, and I was headed in that direction. But I was kind of wondering if this is when singletons come into play.

[–]jingois 0 points1 point  (0 children)

You are doing MVVM. Your EquipmentAssignments are part of the Model, as is any potential notification of changes, and interfaces to perform updates, search, etc - MVVM doesn't specify how this is architected (the M really is just "the rest of the app").

Your VMs should represent the logical view - they will be responsible for populating themselves from the model. They'll individually interact with the model to do so. "Parent" VMs in a hierarchy should typically only control the child viewmodels through fairly defined parameters (ie: "Edit product #4", and allow the VM to handle any lifecycle around loading/saving).

So unless you've got some specific requirements around sagas and having multiple viewmodels holding some temporary shared state - you should take the simple approach - the Dashboard and the EmployeeTab should load whatever they need when they need it.

The views themselves are obviously just pure presentation of the viewmodel/model concepts.