一、带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));
参考:
WPF CommunityToolkit.Mvvm Messenger通讯-CSDN博客
Messenger - Community Toolkits for .NET | Microsoft Learn
标签:CommunityToolkit,Mvvm,Default,WeakReferenceMessenger,Messenger,消息 From: https://www.cnblogs.com/chao-ye/p/17911368.html