MVVM light toolkit messenger problems
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.
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.
You could set the target of the message if your message inherits from MessageBase
class,
or use a Guid
as a Messenger token.
精彩评论