当前位置:网站首页>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.
边栏推荐
- A,H,K,N
- 爬虫基本原理介绍、实现以及问题解决
- Induction jian hai JustFE 2022/07/29 team, I learned the efficient development summary (years)
- MySQL-Data Definition Language-DDLdatebase define language
- Robot_Framework: keyword
- CSP-S2019 Day1
- vim configuration + ctag is as easy to read code as source insight
- 对话MySQL之父:一个优秀程序员可抵5个普通程序员
- Selenium: upload and download files
- Using FiddlerScript caught poly FiddlerScript 】 【 download
猜你喜欢
随机推荐
Jupyter shortcuts
Vsce package after the Command failed: NPM list - production - parseable - the depth = 99999 - loglevel = error exception
uva10825
Dell PowerEdge Server R450 RAID Configuration Steps
从底层结构开始学习FPGA(6)----分布式RAM(DRAM,Distributed RAM)
AspNet.WebApi.Owin custom Token request parameters
微信小程序获取手机号phonenumber.getPhoneNumber接口开发
仿牛客网讨论社区项目—项目总结及项目常见面试题
NUMPY
小白的0基础教程SQL: 什么是SQL 01
Jupyter shortcuts
解决浏览器滚动条导致的页面闪烁问题
Robot_Framework:关键字
中国的机器人增长
Qt Widget 项目对qml的加载实例
LeetCode 0150. 逆波兰表达式求值
测试工具(四)Jenkins环境搭建与使用
LeetCode Question of the Day (309. Best Time to Buy and Sell Stock with Cooldown)
使用string 容器翻转 字母
爬虫框架 Scrapy 详解








