0
votes

I ran into bizzare problem. I register receiving a message as follows:

        Messenger.Default.Register<CreatedPatientMessage>(this, x =>
        {
            CurrentViewModel = targetLeftViewModel;
        });

and send a message like below

Messenger.Default.Send<CreatedPatientMessage>(new CreatedPatientMessage());

Unfortunately it never reaches that message. I made sure it is registered before message is sent. What weird is, that if I remove below line

CurrentViewModel = targetLeftViewModel;

and paste something like

var name = "";

and set breakpoint on it, it stops there, otherwise it does not.

1

1 Answers

0
votes

It took a while but I came up with solution. I registered receiving message in constructor as follows:

 public Patient(BaseViewModel targetLeftViewModel, BaseViewModel targetRightViewModel)
    {
        this.TargetRightViewModel = targetRightViewModel;
        Messenger.Default.Register<CreatedPatientMessage>(this, x =>
        {
            CurrentViewModel = TargetRightViewModel;
        });
    }

Above definition works but when you change body responsible for receiving message to this:

CurrentViewModel = targetRightViewModel

It will not. It turns out, that parameter sending to constructor is then removed from memory and when a need to use it occurs it cannot be retrieved and I guess that is why it never reached that. When I saved it in property (TargetRightViewModel), in order to save its value, it works as expected.