I'm using this :
Messenger.Default.Send<NameMessage>(new NameMessage("Test"));
This message is register in two View models.
ViewModel 1 :
Messenger.Default.Register<NameMessage>(this, MethodInMyViewModel1);
ViewModel 2 :
Messenger.Default.Register<NameMessage>(this, MethodInMyViewModel2);
When I send the message, the Two Methods are called.
But I have an Instance of my view at each time.
So the application stop.
How can I call a specific view model with the same message ?
Assuming you are talking about the mvvmlight messenging namespace, you could always send the same message with different value based on which VM you are targeting, so each VM should register like so (the one bellow is for VM1):
Messenger.Default.Register<NameMessage>(this, (m) =>
{
switch (m.Value)
{
case "VM1":
MethodInMyViewModel1();
break;
}
});
Do the same for VM2, and when sending the message pass the appropriate targeted VM message to the NameMessage Value
.