1

Hello I got a simple message that I'm trying to deliver between classes:

  public class MainVM : ObservableRecipient, IRecipient<SaveMessage>
    {
        
        public void Receive(SaveMessage message)
        {
            Console.WriteLine(message.Value);
        }
    }

And this code in a different class:

[RelayCommand]
public void SendToDbSave()
{
    WeakReferenceMessenger.Default.Send(new SaveMessage(Result.ToString()));

}

Basically the message gets sent, but doesn't get received, the method doesn't get invoked. Any idea why?

Jim Foye
  • 1,918
  • 1
  • 13
  • 15
AntiMatter
  • 13
  • 5

1 Answers1

0

try set IsActive=true.

the document explained the IsActive Property:

"It exposes an IsActive property to activate/deactivate the viewmodel. In this context, to "activate" means that a given viewmodel is marked as being in use, such that eg. it will start listening for registered messages, perform other setup operations"

 public class MainVM : ObservableRecipient, IRecipient<SaveMessage>
 {
     public MainM()
     {
         IsActive=true;
     } 

     public void Receive(SaveMessage message)
     {
         Console.WriteLine(message.Value);
     }
}
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 13 '23 at 18:40