Your syntax will look something like this:
//Subscribe Messenger.Default.Register<OpewNewWindowMessage>(OpenNewWindowMethod); // Broadcast var message = new OpewNewWindowMessage(); message.ViewModel = this; Messenger.Default.Send<OpewNewWindowMessage>(message); // Subscribed method would look like this void OpenNewWindowMethod(OpewNewWindowMessage e) { // e.ViewModel would contain your ViewModel object }
In the above example, you must create a new class named OpewNewWindowMessage and assign the ViewModel property to it, then you must fill this value before sending the message.
OpenNewWindowMethod() will receive a message and will be able to access OpewNewWindowMessage.ViewModel to access the ViewModel property
Technically, you donβt need to create a message object if you bypass only one property, but usually I find it makes it easier to read and maintain the code if you create a message object instead of using a common <object> like you have in your code.
source share