Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Struggling to understand MVVM architecture

I'm trying to learn MVVM and WPF and I'm using the MVVM Light Toolkit. Here's what I'm not fully understanding and maybe it's due to an incorrect architecture of my UI.

What I'm trying to accomplish is pretty simple actually. This is a utility application by the way. I want a window that serves as the 'controller' so-to-say that has a set of buttons. Each button should change the content of a frame. Example: one button loads a 'screen' ( or a 'view' if you will ) that allows the user to configure an 'Agency' which is a custom object. Another button loads a list of Users from the Agency that was in the first 'screen'. This 'Users' view needs to also be loaded in the same frame. In fact, as of right now, the window with all the buttons really is only responsible for loading the 'screens' in the frame. The meat of the application will be within all the separate 'screens'

What I am not understanding is 1) how to let each screen/view know about each other since one is dependent upon the other. It seems that in MVVM the ViewModel shouldn't know about anything. But in my case, I need to pass information around ( such as my Agency ).

If I can get some hints on what I need to look into, that would be great.

Thanks!

like image 224
ABR Avatar asked Nov 16 '11 18:11

ABR


1 Answers

Some ideas that might connect some of the dots:

  • You'll most likely have one viewmodel per view ("screen").
  • Each viewmodel will contain all of the logic for its corresponding view
  • Viewmodels can and will know about the models (Agency, Users)
  • Viewmodels can communicate with each other via the Messenger in MVVM Light
  • Think of MVVM Light's Messenger as an "application-wide eventing system". When you send a message out from one view model, any other view model can be listening for that message/event and react to it as needed.

Does that help at all? Keep your thoughts coming and I'll keep commenting and I'm sure the community will as well :)

like image 51
Kendrick Avatar answered Oct 02 '22 16:10

Kendrick