当前位置:网站首页>(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
边栏推荐
- C#【高级篇】 C# 泛型(Generic)【需进一步补充:泛型接口、泛型事件的实例】
- How do college students make money by programming| My way to make money in College
- Installation and use of yarn
- C # [advanced chapter] C # anonymous method [lambda expression to be supplemented...]
- 51 single chip microcomputer indoor environment monitoring system, mq-2 smoke sensor and DHT11 temperature and humidity sensor, schematic diagram, C programming and simulation
- Learning cyclic redundancy CRC check
- [punch in - Blue Bridge Cup] day 4--------- split ('') cannot be used. There is a space after the last number of test cases. Split ()
- 专升本语文资源整理
- 11: I came out at 11:04 after the interview. What I asked was really too
- 云原生——Web实时通信技术之Websocket
猜你喜欢
Realization of BFS in C language by storing adjacency matrix of graph
Analysis of similarities and differences of various merged features (Union, merge, append, resolve) in ArcGIS
[note] Introduction to data analysis on June 7, 2022
Redis在windows系统中使用
(Reprinted) an article will take you to understand the reproducing kernel Hilbert space (RKHS) and various spaces
Litjson parses the generated JSON file and reads the dictionary in the JSON file
Product thinking - is the future of UAV express worth looking forward to?
Hudi record
Laravel9 local installation
1152_ Makefile learning_ Pattern matching rules
随机推荐
Analysis of similarities and differences of various merged features (Union, merge, append, resolve) in ArcGIS
How do college students make money by programming| My way to make money in College
Hisense A7 ink screen mobile phone cannot be started
What are the defaults for Binding. Mode=Default for WPF controls?
Version correspondence table of tensorflow, CUDA and bazel
Tidb 6.0: rendre les GRT plus efficaces 丨 tidb Book Rush
【论文阅读|深读】Role2Vec:Role-Based Graph Embeddings
Laravel9 local installation
(04).NET MAUI实战 MVVM
绿色新动力,算力“零”负担——JASMINER X4系列火爆热销中
[punch in - Blue Bridge Cup] day 4--------- split ('') cannot be used. There is a space after the last number of test cases. Split ()
Solutions for project paths
EasyCVR部署服务器集群时,出现一台在线一台不在线是什么原因?
[frequently asked questions] modularization of browser environment and node environment
LitJson解析 生成json文件 读取json文件中的字典
关于智能视觉组上的机械臂
【笔记】2022.5.23 MySQL
.NET 7 的 JWT 配置太方便了!
Radiant energy, irradiance and radiance
[punch in - Blue Bridge Cup] day 5 --- lower() small