EventAggregator template: how to transfer data?

I am considering using an event aggregation pattern in a user interface project that I am working on (Silverlight / MVVM) to maintain a loose connection between views / view modes. We wrote several screens using a simple eventing system - this is nothing more than a proof of concept at the moment, but it seems like a very elegant solution for creating a loosely coupled system.

The problem I am facing is transferring data from one ViewModel to another when the receiving ViewModel has not yet been created. For example, if the customer list screen is open, the user can click on a specific client to open the screen for editing / viewing customer data (possibly in a child window). The Customer Detail screen requires a customer (or customer ID) to work.

So, it seems reasonable that OpenCustomerDetailEvent will contain relevant customer information, but what are some options for entering this information into Customer Detail V / VM? Since it is not yet in memory when the event is being processed, it cannot directly listen to the event (it itself cannot be a handler). We use an injection container to create a presentation and presentation model (currently we see “first”), so having a separate handler for entering data through the constructor is not a great option.

What are some other options for getting data in a view (model) after it's created? An init method that uses strongly typed parameters? Using the installer to enter data? When will the handler create the V / VM and then send the second event that the virtual machine is listening to?

+3
source share
1 answer

For this, I use Prism in a Silverlight application. It provides an implementation of the EventAggregator pattern and view navigation infrastructure.

NavigationParameters, /viewmodel, . view/viewmodel , EventAggregator , .

, , .

.

+2

All Articles