Hello,
Comparing the official documentation, the reason for your failure should be that you did not set up a clear information structure. I tested with the following code and it works.
Messenger class:
public class User
{
public Dictionary<string, string> keyValuePairs;
}
public class LoggedInUserChangedMessage : ValueChangedMessage<User>
{
public LoggedInUserChangedMessage(User user) : base(user)
{
}
}
Register:
try
{
WeakReferenceMessenger.Default.Register<LoggedInUserChangedMessage>(this, (r, m) =>
{
OnMessageReceived(r, m);
});
}
catch (Exception ex)
{
; // ex.Message == "The target recipient has already subscribed to the target message."
}
public void OnMessageReceived(object sender, LoggedInUserChangedMessage payLoad)
{
// process the message sent via payLoad string Dictionary
}
Unregister:
WeakReferenceMessenger.Default.Unregister<LoggedInUserChangedMessage>(this);
Best Regards,
Alec Liu.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.