I am working on WPF MVVM application wherein I have 2 views View1 and View2 with their respective ViewModels. Now, I want on click of a button in View1 would close View1 and open View2 using ViewModel1.
Also, I want to pass some data say a instance of person class to ViewModel2 when opening from ViewModel1 which would be used to display information in View2.
What is the best and possibly the simplest way to achieve this inside ViewModels only, I would want to avoid writing code for navigation in code behind.
Best Answer
I created this
Messenger
class to handle communication between ViewModels.Register for an added person object in
MainViewModel
:To notify all registered ViewModels about the added person from the
CreatePersonViewModel
:Source code: