0
votes

I'm using your messenger class to communicate between views/controls and viewmodels. Currently I have the same usercontrol multiple times on the same view. The problem is that when one viewmodel sends a message back to the usercontrol then all of the usercontrols (of that same type) in my view get updated. How can this be prevented?

FYI, I played around with the token functionality that you provide, but I couldn't make it work for my particular case.

2

2 Answers

0
votes

Have you tried altering your usercontrol so that upon construction, you can specify whether or not it should Register for that particular message? I would do that as a starting point.

Another thing to watch out with using Messenger.Default -- it isn't threadsafe, so if you end up using it in lots of places other than usercontrols (like in worker threads to notify the main thread of events happening), then you had better wrap it in another class that performs the requisite locking.

0
votes

You could set the target of the message if your message inherits from MessageBase class, or use a Guid as a Messenger token.