3

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?

Community
  • 1
  • 1
DanteTheEgregore
  • 1,530
  • 5
  • 23
  • 44

1 Answers1

8

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.

dm88
  • 382
  • 2
  • 13
  • "Make sure that you first REGISTER the message before you send it." -> the most useful keyword.Thanks a lot!! – anevil Mar 04 '15 at 02:50