New answer
As OP (Daryl) pointed out, my initial answer (see below) was not quite right, so I am providing a new answer if someone comes up with the same problem later:
It makes sense that if you have two instances of what is being registered for the same message type with the same token, both instances will receive the message. The solution is to provide a marker that is unique to each pair of View-ViewModel.
Instead of using a simple enumeration value as a token, you can put the value of your name in a class, for example:
public class UniqueToken { public MessengerToken Token { get; private set; } public UniqueToken(MessengerToken token) { Token = token; } }
Then in your ViewModel add a new property to store one of these unique tokens:
Finally, in your view, you can now grab a unique token and use it to register for an OpenWindow message:
var viewModel = (MyViewModel)DataContext; var token = viewModel.OpenWindowToken; Messenger.Register<TMessage>(this, token, message => OpenWindow(message));
For ViewModel and View, you need to use the same instance of UniqueToken, because the messenger will only send a message if the token token of the receiver and the token of the sender are the same object, and not just instances with the same property values.
Original answer (not entirely correct)
I think there might be a typo in your question: you say that to open a new window you send a message from the ViewModel to the view, but then you say that both ViewModels receive the message. Did you mean that both species receive a message?
In any case, it makes sense that if you have two instances of what is being registered for the same type of messages with the same token, both instances will receive the message.
To solve this problem, you first need each instance of your ViewModel to have a unique identifier. This can be done using Guid . Sort of:
Then you need your token to be an object that has two properties: one for guid and one for the enumeration value:
public class UniqueToken { public Guid Id { get; private set; } public MessengerToken Token { get; private set; } public UniqueToken(Guid id, MessengerToken token) { Id = id; Token = token; } }
Then, when you register in your view (or is it your ViewModel?), You need to grab the Guid from the ViewModel. This may work as follows:
var viewModel = (MyViewModel)DataContext; var id = viewModel.Id; var token = new UniqueToken(id, MessengerToken.OpenWindow); Messenger.Register<TMessage>(this, token, message => OpenWindow(message));
Finally, in your ViewModel you need to do something like this:
var token = new UniqueToken(Id, MessengerToken.OpenWindow); Messenger.Send(message, token);
Edit
After entering all this, it occurred to me that you really don't need the Id property in the ViewModel. You can simply use the ViewModel itself as a unique identifier. So, for UniqueToken you can just replace public Guid Id with public MyViewModel ViewModel , and it should work anyway.