MVVM Light Messenger Not Functioning As Expected

[亡魂溺海] 提交于 2019-12-06 11:04:54

问题


A while back I asked a question found here: Use MVVM Light's Messenger to Pass Values Between View Model

I went to test the answer today and it doesn't appear to be working. My implementation looks as follows:

MessengerInstance.Send(SelectedDocument, Model.StaticEnums.Tokens.SettingstoMain);

And:

MessengerInstance.Register<XDocument>(this, Model.StaticEnums.Tokens.SettingstoMain, settings => CopySettings(settings));

My problem is, this implementation doesn't work. Instead, the arguments for MessengerInstance.Send and MessengerInstance.Register both appear to be strikingly different from the implementation in the answer.

What am I doing wrong here? Is the implementation in the answer to my previous question correct?


回答1:


I didn't worked a lot with MVVM light in the past few months. But I send and registered messages always this way (see code). Maybe there are better ways in the new version. But I don't think.

GalaSoft.MvvmLight.Messaging.Messenger.Default.Register<string>(this, (a) => { MessageBox.Show(a); });

GalaSoft.MvvmLight.Messaging.Messenger.Default.Send<string>("abc");

Make sure that you first REGISTER the message before you send it.

EDIT: For each message type I created a custom message class. So it's easier to find in the code where the message is used in the application.



来源:https://stackoverflow.com/questions/18241290/mvvm-light-messenger-not-functioning-as-expected

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