CommunityToolkit.Mvvm8.1 message notification(4)

CommunityToolkit.Mvvm8.1 message notification(4)

CommunityToolkit.Mvvm8.1 message notification (4) Navigation of this series of articles https://www.cnblogs.com/aierong/p/17300066.html https://github.com/aierong/WpfDemo (self-Demo address) I hope the knowledge mentioned can give you some hints, and welcome to communicate and correct. Author: aierongSource: https://www.cnblogs.com/aierong Description In order to separate different modules of the application and reduce references between modules, CommunityToolkit.Mvvm provides a message notification function, which can facilitate data transfer between modules. Send a message Method: WeakReferenceMessenger.Default.Send The official recommendation is to use ValueChangedMessage to encapsulate data transmission //Send send message WeakReferenceMessenger. Default. Send( “qq1” ); //Special attention: directly passing the value can only be a reference type, and the value type cannot be compiled successfully (for example: the following 2 sentences will not work) //WeakReferenceMessenger.Default.Send(11, “token_1”); //WeakReferenceMessenger.Default.Send(true, “token_1”); //The above is also possible, but the official recommendation is to use ValueChangedMessage to encapsulate data transfer WeakReferenceMessenger.Default.Send<ValueChangedMessage , string>( new ValueChangedMessage( “qq1 from UserControlLeftViewModel”) , “token_1” ); It is recommended to bring the token name when sending messages, so that it is convenient for subscription receivers to filter data WeakReferenceMessenger.Default.Send<ValueChangedMessage , string>( new ValueChangedMessage( “qq1 from UserControlLeftViewModel”) , “token_1” ); Send message passing object public class MyUserMessage { public string UserName { get; set; } public int Age { get; set;…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索