C
C#2y ago
Kosta

✅ Mvvm toolkit - messenger not working? Recive messege not invoked

Hey there im trying to recieve a simple messege using messenger Got this code:
if (Result == 1) {
SendToDbSave();
}

}

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

}
if (Result == 1) {
SendToDbSave();
}

}

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

}
public class MainVM : ObservableRecipient, IRecipient<SaveMessege>
{
public void Receive(SaveMessege message)
{
Console.WriteLine(message.Value);
}
}
public class MainVM : ObservableRecipient, IRecipient<SaveMessege>
{
public void Receive(SaveMessege message)
{
Console.WriteLine(message.Value);
}
}
So why dont i ever go into the recive messege? i do send the messege, but debug point wont go into recive method
2 Replies
Klarth
Klarth2y ago
I would try registering to receive the message. I don't quite remember when/if it's automatically setup. Make a ctor in MainVM for either:
Messenger.RegisterAll(this);
Messenger.RegisterAll(this);
Or
Messenger.Register<SaveMessege>(this, (r, m) => Receive(m));
Messenger.Register<SaveMessege>(this, (r, m) => Receive(m));
Kosta
KostaOP2y ago
Well i've managed to solve it with Dependency injection, needed to initilaze the class lol forgot

Did you find this page helpful?