3

I have an app that presents many view-viewModel pairs based on the same view and viewModel. (ie there are many view -> viewModel instance pairs)

I can use the Messenger to send/register messages from viewModel to view, and when I send a message from a view, it is processed by all the views (They all register for the message).

How would I use the Messenger to send a message from the viewModel to the specific view that created the viewModel? (All the views have registered for the message, but I only want one of the views to process the message)

  • According to the documentation, messages are only received by the objects registered to listen for messages of the same type. Can you try creating child message classes and implement registration and sending for those types? Or does your program need to allow multiple instances of the same view be available? http://blog.galasoft.ch/archive/2009/09/27/mvvm-light-toolkit-messenger-v2-beta.aspx – Jesslyn May 23 '12 at 20:58

1 Answers1

1

You can use the Token while sending and registering Messaging.

Suppose You have to pass Message From ViewModel to ABCView then you can use Messenging like this..

For Ex, if you have to pass boolean value then use:

Messenger.Defalut.Send<bool>(true,"ForAbcView");

And in ABCView you can register like this:

Messenger.Default.Register<bool>(this,"ForAbcView",(b)=>{ //Some Code });

With using Token the Messenger Sender will only looks for the Register which will have same token. It only calls the method which will have same tocken.

R76
  • 446
  • 6
  • 25