当前位置:网站首页>(04). Net Maui actual MVVM
(04). Net Maui actual MVVM
2022-06-30 03:48:00 【Dotnet cross platform】
1. Summary
This chapter will explain how to MAUI Use the simple MVVM Pattern development “ListView” Content addition and deletion function ,MVVM stay MAUI The same applies to .

Microsoft.Toolkit.Mvvm
Before we study, let's learn about nuget package , It can help us save some code development time . package Microsoft.Toolkit.Mvvm (aka MVVM Toolkit) It's a modern 、 Fast 、 Modular MVVM library . This package is for .NET Standard, In order to use it on any application platform :UWP、WinForms、WPF、Xamarin、Uno etc. ; At any run time :.NET Native、.NET Core、.NET Framework or Mono. It runs on all . In all cases ,API The surfaces are the same , Therefore, it is very suitable for generating shared libraries . In Solution Explorer , Right click on the item , And then choose “ management NuGet package ”. Search for Microsoft.Toolkit.Mvvm And install it .

2. The detailed content
Project

View
<Grid RowDefinitions="500,50">
<ListView ItemsSource="{Binding Temps}"/>
<StackLayout Grid.Row="1">
<Button WidthRequest="100" HeightRequest="25" Text="add" Command="{Binding AddCommand}"/>
<Button WidthRequest="100" HeightRequest="25" Text="add" Command="{Binding DeleteCommand}"/>
</StackLayout>
</Grid>ViewModel
//ViewModel Need to inherit
public class MainViewModel : ObservableObject
{
private string _test;
private ObservableCollection<MainModel> _temps;
private ICommand addCommand;
private ICommand deleteCommand;
// Data notification collection
public ObservableCollection<MainModel> Temps { get => _temps; set => _temps = value; }
// command
public ICommand AddCommand { get => addCommand ?? (addCommand = new RelayCommand(AddCallback));}
public ICommand DeleteCommand { get => deleteCommand ?? (deleteCommand = new RelayCommand(DeleteCallback)); }
// Data notification fields
public string Test { get => _test; set => SetProperty(ref _test , value); }
public MainViewModel()
{
// initialization
Temps = new ObservableCollection<MainModel>();
Temps.Add(new MainModel { Name = "zhangsan" });
Temps.Add(new MainModel { Name = "zhangsan" });
}
// Command execution content
private void AddCallback()
{
Temps.Add(new MainModel { Name = DateTime.Now.ToString() });
}
private void DeleteCallback()
{
Temps.RemoveAt(0);
}
}Model
public class MainModel
{
public string Name { get; set; }
public override string ToString()
{
return Name;
}
}Run

边栏推荐
- Laravel9 local installation
- A minimalist way to integrate databinding into activity/fragment
- Linear interpolation of spectral response function
- [operation] getting started with MySQL on May 23, 2022
- X Book 6.89 shield unidbg calling method
- TiDB 6.0:讓 TSO 更高效丨TiDB Book Rush
- 绿色新动力,算力“零”负担——JASMINER X4系列火爆热销中
- [punch in - Blue Bridge Cup] day 2 --- format output format, ASCII
- Number of students from junior college to Senior College (III)
- matplotlib. pyplot. Hist parameter introduction
猜你喜欢

Stc89c52/90c516rd/89c516rd ADC0832 ADC driver code

Buffer pool of MySQL notes

Arrangement of language resources of upgraded version

Learning cyclic redundancy CRC check

Interface test tool postman

Node-RED系列(二八):基于OPC UA节点与西门子PLC进行通讯

声网自研传输层协议 AUT 的落地实践丨Dev for Dev 专栏

MySQL performance optimization (5): principle and implementation of master-slave synchronization

Simple theoretical derivation of SVM (notes)

Redis在windows系统中使用
随机推荐
巧用 Bitmap 实现亿级海量数据统计
Mysql性能优化(6):读写分离
【笔记】2022.6.7 数据分析概论
【力扣刷题总结】数据库题目按知识点分类总结(持续更新/简单和中等题已完结)
dbt产品初体验
Stc89c52/90c516rd/89c516rd ADC0832 ADC driver code
C # [advanced chapter] C # anonymous method [lambda expression to be supplemented...]
UML图与List集合
Half a year after joining the company, I was promoted to a management post
DO280私有仓库持久存储与章节实验
Redis在windows系统中使用
Product thinking - is the future of UAV express worth looking forward to?
【笔记】2022.5.27 通过pycharm操作MySQL
Tidb 6.0: making Tso more efficient tidb Book rush
C [advanced part] C generic [need to be further supplemented: generic interfaces and instances of generic events]
Using virtual environments in jupyter notebook
The jupyter notebook kernel hangs up frequently and needs to be restarted
Postman learning sharing
Hudi record
[note] Introduction to data analysis on June 7, 2022