CommunityToolkit.Mvvm8.1 viewmodel source generator writing (3)

CommunityToolkit.Mvvm8.1 viewmodel source generator writing (3)

CommunityToolkit.Mvvm8.1 viewmodel source generator writing (3) 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 The most surprising thing about CommunityToolkit.Mvvm8.1 is the source generator function it provides, which greatly simplifies our mvvm codeWe can realize a certain function by marking an attribute, which is very convenient and fast. Recommended Summary of commonly used tags1. Inherit ObservableObject and the class tag is partial class2. Private variable tag property [ObservableProperty]3. NotifyCanExecuteChangedFor Notify dependency command NotifyPropertyChangedFor Notify dependency property br>4.RelayCommand define command5.OnPropertyChanged manually notify property update6.ButtonClickCommand.NotifyCanExecuteChanged() manually notify command update7.OnLastNameChanging OnLastNameChanged a property change8.OnPropertyChanged all properties change Define viewmodel When defining vm, please use partial class and inherit ObservableObject public partial class DataViewModel2 : ObservableObject { } ObservableProperty tag attribute Defining properties is so simple: a [ObservableProperty] tag is done /* After the [ObservableProperty] mark, the attribute (named in uppercase) will be automatically generated, for example: the following will automatically generate Title Note: This private variable name: must start with lowercase, or underscore, or m_ */ [ObservableProperty] private string title = “hello”; //public string Title //{ // get // { //…

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
首页
微信
电话
搜索