当前位置:网站首页>MVVM project development (commodity management system 1)
MVVM project development (commodity management system 1)
2022-08-01 06:02:00 【Pzz_Lite】
MVVM项目开发(A commodity management system)
注:下面使用 Microsoft Visual Studio2022,Some knowledge points are quoted from the tutor's teaching,I have the complete system and in my resourcesSQLFree download of databases and database physical models.
一、MVVM页面搭建
1.(1)、First, create a home page,在项目“解决方案资源管理器”One is created by default in “MainWindow.xaml”窗口,You can now delete the file and recreate a window with the same name.
2.页面加载事件,C#事件:Event.
(1)、如一个“确定”The button click action will trigger a button click event to complete the execution of the corresponding code to achieve the login function.
(2)、事件是一种引用类型,实际上也是一种特殊的委托. 通常,每一个事件的发生都会产生发送方和接收方,发送方是指引发事件的对象,The recipient is the recipient 取、处理事件.事件要与委托一起使用.
(3)、由于在事件中使用了委托,因此需要在定义事件前先定义委托. 在定义事件后需要定义事件所使用的方法,并通过事件来调用委托.
(4)、例1:The input is done on the console via events“Hello Event!”的操作.
class Program {
//定义委托 public delegate void SayDelegate();
//定义事件 public event SayDelegate SayEvent;
//定义委托中调用的方法 public void SayHello()
{
Console.WriteLine(“Hello Event!”);
}
//创建触发事件的方法 public void SayEventTrigger()
{
//触发事件,必须与事件是同名方法 SayEvent();
}
static void Main(string[] args)
{
//创建Program类的实例 Program program = new Program();
//实例化事件,使用委托指向处理方法 program.SayEvent = new SayDelegate(program.SayHello);
//调用触发事件的方法 program.SayEventTrigger();
}
}
3.(1)、Create a page load event on the created page,This event is used to load page data.
(2)、The drop-down box needs to be connected to another table,So when the page is laid out, you need to bind another table to the drop-down boxid,and add an event.
(3)、在项目“解决方案资源管理器”的“ViewModel”Create a new class in the folder,This class is used for data display and addition on the main page of the project、修改、删除、查找、Import and export the background implementation code.
(4)、After the page is laid out,Right-click in the code“查看代码”Go to page is the background class,Then instantiate the pageViewModelThe control code class name in .
(5)、in the background class,首先引用“ViewModelBase”MvvmLight的命名空间,然后在“MainWindowViewModel”A command that declares a page in a method is equal to a method,And facilitate the separation of properties and methods,Intentionally use the method of code block folding for classification.
4.命令
(1)、MVVMLight:命令基础 在MVVM Light框架中,事件是WPF应用程序中UI与后台代码进行交互的最主要方式,Not with the traditional way 同,mvvm中主要通过绑定到命令来进行事件的处理.
(2)、RelayCommand命令: WPF命令是通过实现 ICommand 接口创建的. ICommand 公开了两个方法(Execute 及 CanExecute)和一个事件(CanExecuteChanged).
5.WMVMThe modal uses bindings for keyboard and mouse events
(1)、InputBindings:Gets the collection of input bindings associated with this element.The content is one or more InputBinding 元 素(通常为 KeyBinding 或 MouseBinding 派生类). Each of them should have 有 Command 和 Gesture 属性集.
(2)、下面需要注意的是:The input text in the search text box is pressedEnterAfter the event will fire though,但是获取不到 The input text value of the search text box,So what needs to be is the input text of the search textbox is pressedEnterafter losing focus,以 添加PreviewKeyDown="SearchBox_OnKeyDown.
例:代码
<TextBox x:Name=”SearchBox”Text=”{Binding SearchText}”Width=”200”Height=”25” HorizontalAlignment=”Right” PreviewKeyDown=”SearchBox_OnKeyDown”>
<TextBox.InputBindings>
<KeyBinding Command=”{Binding KeyEventCommand}” Key=”Enter”/>
dxg:GridControl.InputBindings
<MouseBinding Command=”{Binding ProductDoubleClickCommand}” CommandParameter=”{Binding ElementName=ProductCtrl,Path=CurrentItem} ”
MouseAction=”LeftDoubleClick”/>
</dxg:GridControl.InputBindings>
</TextBox.InputBindings>
(6)、数据库引用
(1)、在ModelRight-click to add a new item.
(2)、点击数据–>ADO.NET 实体数据模型–.>命名数据库.
(3)、默认为第一个.
(4)、建立数据库连接,database name andSQL Server The database name of the database that stores the system is the same,Then the account and password to log in to the database,And select the database corresponding to the system.
(5)、Tick to accept sensitive data connected to the database,Keep the default naming below(也可以自定义命名)下一步.
(6)、使用最新的框架,
(7)、Check all database tables for this system,The following namespaces are default(可以自定义命名)点击完成,Then the database reference is done.
(8)、属性引用,when writing properties,输入propfullThen double-clickTabkey to quickly add property code blocks.
(9)、全局变量中,实例化数据模型,输入Model.That is, the database model can be referenced,并且使用“readonly”The keyword sets read-only permissions for this database,If this keyword is not added, it defaults to read and write permissions.
边栏推荐
猜你喜欢
牛客刷SQL---2
对话MySQL之父:一个优秀程序员可抵5个普通程序员
Robot_Framework:关键字
WPF项目-初步了解数据绑定 binding
NDK does not contain any platforms problem solving
Sound Signal Processing Fundamental Frequency Detection and Time-Frequency Analysis
About making a progress bar for software initialization for Qt
可视化全链路日志追踪
leetcode125 验证回文串
leetcode125 Verify palindrome string
随机推荐
Matlab simulink particle swarm optimization fuzzy pid control motor pump
安装SQL Server详细教程
matlab simulink 粒子群优化模糊pid控制的电机泵
Selenium: mouse, keyboard events
响应式织梦模板园林景观类网站
Selenium: element judgment
声音信号处理基频检测和时频分析
曲柄滑块机构运动分析和参数优化
WPF入门项目必知必会-初步了解数据绑定 binding
中国的机器人增长
vim configuration + ctag is as easy to read code as source insight
torch
湖仓一体电商项目(一):项目背景和架构介绍
Selenium: Introduction
从底层结构开始学习FPGA(6)----分布式RAM(DRAM,Distributed RAM)
NDK does not contain any platforms问题解决
权重等比分配
Dialogue with the father of MySQL: One excellent programmer is worth 5 ordinary programmers
微信小程序接口调用凭证(获取token)auth.getAccessToken接口开发
Selenium: Manipulating Cookies