MVVM Central App Logic

I use the Simple MVVM Toolkit in WPF to create an application, the application uses a central tab control, with a View (UserControl) element for each tab element. These views may also contain tab controls that contain additional “sub-views.”

Our difficulty lies in finding a way to share application logic that is used by several of these representations, without having one global huge messy class.

+3
source share
1 answer

I would not go with a huge class that holds everything. But I would have a central ViewModel that controls the overall state. Like ShellViewModel. And I will allow viewmodels to communicate and exchange information through Messenger (MVVM Toolkit light) or EventAggregator (Prism). They offer a way to publish a subscriber template for sharing information. And you can access them by implementing your own message classes and passing the payload along with it.

So, you can have a global message to save each and every (Sub-) ViewModel, which can register on it and run its own save method after receiving the message ...

Prism http://msdn.microsoft.com/en-us/library/ff921122(v=pandp.20).aspx

MVVM http://blog.galasoft.ch/archive/2009/09/27/mvvm-light-toolkit-messenger-v2-beta.aspx

, ...

+2

All Articles