I've just started learning Silverlight with the MVVM Light framework. Most recently I've started getting into the Messenger features in MVVM Light.
So far I've downloaded and dug into the Clean Shutdown example posted by Laurent and have a basic understanding of how the Messenger class works but I'm still a little unsure when to use which Message type.
From the site, here are the Message types:
- MessageBase: A simple message class, carrying optional information about the message's sender.
- GenericMessage: A simple message with a Content property of type T.
- NotificationMessage: Used to send a notification (as a string) to a recipient. For example, save your notifications as constant in a Notifications class, and then send Notifications.Save to a recipient.
- NotificationMessage: Same as above, but with a generic Content property. Can be used to pass a parameter to the recipient together with the notification.
- NotificationMessageAction: Sends a notification to a recipient and allows the recipient to call the sender back.
- NotificationMessageAction: Sends a notification to a recipient and allows the recipient to call the sender back with a generic parameter.
- DialogMessage: Used to request that a recipient (typically a View) displays a dialog, and passes the result back to the caller (using a callback). The recipient can choose how to display the dialog, either with a standard MessageBox, with a custom popup, etc…
- PropertyChangedMessage: Used to broadcast that a property changed in the sender. Fulfills the same purpose than the PropertyChanged event, but in a less tight way.
My question is this: Can anyone explain to me when I would typically use each of these Message types or point me to an article that breaks down the pros and cons of using each message type?
You will save your self a lot of headaches and annoyance if you dont try to fit your coding to the messages but make the messages do what you want. Dont be afraid to subclass the messages to make them do what you really want from them. That was one of my first mistakes when using mvvm-light.
Most of my messages use the GenericMessage with the Generic being what I am trying to transfer...
for instance i have an ExceptionMessage class that
Public ExceptionMessage:GenericMessage<System.Exception>
then i override the 3 constructors with the proper values.
I found that its MUCH easier to do it this way than shoehorn things into place.
I have an indepth example here
Its from another question about messaging where I had access to my code...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With