MVVM light messenger does not work as expected

A back I asked a question found here: Use Messenger MVVM Light to pass values ​​between View Model

Today I went to check the answer, and it does not seem to work. My implementation is as follows:

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

and

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

My problem is that this implementation does not work. Instead, the arguments for MessengerInstance.Send and MessengerInstance.Register both seem strikingly different from the implementation in the answer.

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

+2
source share
1 answer

In the past few months, I have not worked very much with MVVM backlighting. But I send and register messages always this way (see Code). There may be better ways in the new version. But I do not think so.

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

Before sending, be sure to register the message first.

EDIT: for each type of message, I created my own message class. So it’s easier to find in the code where the message is used in the application.

+7
source

Source: https://habr.com/ru/post/951160/


All Articles