Click here to Skip to main content
15,747,637 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am working on WPF application using MVVM and PRISM. I have multiple views and view models associated with views.
In a view say view1 i have list of data from database in a grid. when i select a record from grid and click on next button my application opens a new view say view2 for details of selected record(like data entry page).

I have to pass id column data from viewmodel1 to viewmodel2, so on page load of viewmodel2 i can get the data for passed id from database.

i have both the views in same module.

please help, also please let me know if i am not clear.

thanks in advance.
Programm3r 29-Nov-11 4:38am    
Does viewmodel1 instantiate / construct viewmodel2? If not, how does it work? In which viewmodel is the next button (ICommand) declared?

Check out the Event Aggregator as part of PRISM:[^]

Essentially, you could have View2 subscribe for a specific navigation notification. The events support adding a "payload" value and it uses generics so you can make the payload whatever you need. View1, when the "Next" button is clicked, would then simply raise the event with the specific column id as the payload. Note that you'll have to raise the event AFTER View2 is created and ready (and, more importantly, subscribed to listen for events). If you are using any kind of dependency injection or service locator then this might get a bit tricky due to the timing, but hopefully this gets you on the right track.
Share this answer
Event aggregators can be a tad heavy on resources, so you could simply pass in the values in the constructors.

Or you could use a common controller class that creates all the view models.
The id could be passed via the controller.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900