mvvmlight でプロジェクトをビルドします。Messenger を使用して、VM または VM と View の間でメッセージを送信します。さて、いつ、どこでメッセンジャーの登録を解除するのだろうか。私を助けてもらえますか?
編集:
これは私のシーンです:
MainWindow と ChildWindow、ChildWindow (2 つの異なる UserControl のいずれかで構成される ContentControl を含む) があり、ChildWindow の SwitchButton を介して ContenControl を変更します。ViewModel に対応するすべてのウィンドウまたは UserControl。
MainViewModel
にメッセージを送信して;MainWindow
を開きます。ChildWindow
MainWindow
を開きChildWindow
(最初に を使用し、 を使用UserControlView1
しないでくださいUserControlView2
)、メッセージを送信しUserControl1ViewModel
て何かを行います。- ユーザーが CancelButton をクリックすると、閉じる
ChildWindowViewModel
メッセージが送信さChildWindow
れます。 ChildWindowViewModel
fireの場合UnloadedCommand
、ChildWindow
それぞれにメッセージを送信しUserControlViewmodel
て何かをクリーンアップします。
メッセンジャーの登録と登録解除の操作は、View または ViewModel のコンストラクタとデストラクタに入れられるか、LoadedCommand と UnloadedCommand のデリゲート メソッドに入れられますか? View の Loaded および Unloaded の LoadedCommand および UnloadedCommand へのコマンド バインド。