When and where to unregister messenger with mvvmlight

六眼飞鱼酱① 提交于 2019-12-06 06:23:06

问题


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.

  1. MainViewModel sends a message to MainWindow to open the ChildWindow;
  2. MainWindow opens the ChildWindow (firstly use UserControlView1, don't use UserControlView2), and send a message to UserControl1ViewModel do something;
  3. If user click the CancelButton, ChildWindowViewModel sends a message to ChildWindow to close;
  4. If ChildWindowViewModel fire UnloadedCommand, ChildWindow sends a message to each of UserControlViewmodel 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.

来源:https://stackoverflow.com/questions/19555266/when-and-where-to-unregister-messenger-with-mvvmlight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!