进一步学习 CommunityToolkit.Mvvm 之 Messenger
一、带token
1. 订阅消息
WeakReferenceMessenger.Default.Register<UserMessage, string>(this, "MyToken", (r, m) =>
{
});
2. 发送消息
WeakReferenceMessenger.Default.Send(new UserMessage(value),"MyToken");
二、某一种数据类型发送接收消息
1. 订阅消息
ViewModel:ObservableRecipient,IRecipient<ValueChangedMessage<bool>>
public void Receive(ValueChangedMessage<bool> message)
{
}
2. 发送消息
WeakReferenceMessenger.Default.Send(new ValueChangedMessage<bool>(value));
参考: