I build a project with mvvmlight. Using Messenger send message between VMs or VM and View. Now, I wonder that when and where to unregister messenger. Could u help me?
Edited:
This is my scene:
There are a MainWindow and a ChildWindow, the ChildWindow (include a ContentControl consist of one of two different UserControl), change the ContenControl via a SwitchButton in ChildWindow. Every window or UserControl corresponding to a ViewModel.
MainViewModel
sends a message toMainWindow
to open theChildWindow
;MainWindow
opens theChildWindow
(firstly useUserControlView1
, don't useUserControlView2
), and send a message toUserControl1ViewModel
do something;- If user click the CancelButton,
ChildWindowViewModel
sends a message toChildWindow
to close; - If
ChildWindowViewModel
fireUnloadedCommand
,ChildWindow
sends a message to each ofUserControlViewmodel
to clean up something.
The operation of register and unregister messenger put in the constructor and the destructor of the View or the ViewModel, or put in the LoadedCommand and UnloadedCommand's delegate methods? View's Loaded and Unloaded's command binding to LoadedCommand and UnloadedCommand.