When and where to unregister messenger using mvvmlight

I am creating a project with mvvmlight. Use a Messenger message to send messages between virtual machines or virtual machines and a view. Now I wonder when and where to unregister the messenger. Could you help me?

Edited by:

This is my scene:

There is MainWindow and ChildWindow, ChildWindow (including a ContentControl consisting of one of two different UserControls), change the ContenControl via SwitchButton to ChildWindow. Each window or UserControl corresponds to a ViewModel.

enter image description here

  • MainViewModelsends the message MainWindowto open it ChildWindow;
  • MainWindowopens ChildWindow(first use UserControlView1, do not use UserControlView2) and send a message UserControl1ViewModelto do something;
  • CancelButton, ChildWindowViewModel ChildWindow ;
  • ChildWindowViewModel fire UnloadedCommand, ChildWindow UserControlViewmodel -.

View ViewModel LoadedCommand UnloadedCommand delegate? Loaded Unloaded LoadedCommand UnloadedCommand.

+3

All Articles