I’m trying to use the mvvm-light messenger capability to open a custom confirm password dialog in my view, triggered by a command in my viewmodel.
I think I understand the usage of Messenger.Default.Register and Messenger.Default.Send.
But how do I get the dialog results back in my viewmodel?
To me the sending seems to be a one way street…
Could someone help a beginner with a small C#/WPF code sample?
Thanks for any help
IMHO it is better to use the
NotificationMessageAction<T>as it is cut out for this task.On the sender side:
And on the receiver side:
I believe that this approach is cleaner as it does not create an unnecessary dependency from the View to the ViewModel (although this way round is not so bad). For better readability consider sub-classing the
NodificationMessageAction<MessageResult>. I.e.Then the sender
and receiver side
becomes a lot clearer.
And verry important unregister the recipient as else you might create a memory leak.