In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to understand. NET MVVM design pattern, I believe that many inexperienced people do not know what to do about it, so this paper summarizes the causes and solutions of the problem, through this article I hope you can solve this problem.
MVVM mode can help you to cleanly separate the business and presentation logic of your program from the user interface. Keeping the program logic separate from the interface can help solve many development and design problems and make your program easier to test, maintain and upgrade. It can also greatly increase code reusability and make it easier for developers and interface designers to cooperate with each other.
Using the MVVM pattern, the UI of the program and the presentation and business logic behind it are separated into three classes:
1-View, encapsulating UI and UI logic
2-Model view, encapsulating presentation logic and state
3-Model, encapsulating the business logic and data of the program
The MVVM pattern is a variant of the presentation-model pattern, which optimizes some of the core features of WPF, such as data binding, data templates, commands, and behavior. In MVVM mode, the view interacts with the view model through data binding and the command line, and changes event notifications. The view model queries, observes and coordinates model updates, transformations, validations, and aggregated data for display in the view.
The following figure shows the MVVM classes and their interactions:
View class
The responsibility of the view is to define the structure and appearance of everything the user can see on the screen. The code behind the ideal view contains only the constructor that calls the InitializeComponent method. Views usually play the following key roles:
Views are visual elements, such as windows, pages, user controls, or data templates
The view defines the controls contained in the view, as well as visualization layers and styles
View applies the view model through the DataContext property
Properties and commands that bind controls and data are exposed by the view model
Views can customize data binding behavior between views and view models
View definition and handling of UI visualization behaviors such as animation
The code behind the view implements visual behavior that is difficult to express in XAML
View model class
The view model encapsulates presentation logic for the view in the MVVM schema, and it does not refer directly to the view or any other implementation or type specific to the view. The view model implements properties and commands to bind the view to data and to remind the view that the state of the view has changed by changing the event notification. The properties and commands provided by the view model define the functionality provided to the UI. But the view defines the function of how to render.
The view model is responsible for coordinating the interaction between the view and any required model classes. Typically, the view model has a lot of relationships with the view class. The view model can choose to expose the model class directly to the view, so the control of the view can be directly data-bound. The view model can transform or manipulate model data so it can be easily used by the view.
Typically, the view model defines commands or behaviors that can be displayed on the UI and invoked by the user. A common example is that when the view model needs to submit commands, it allows users to submit data to a network service or database. The view can choose to display with a button so that the user can click the button to submit the data. Typically, when command programming is not available, its associated UI presentation becomes unavailable. View models typically play the following key roles:
Model view is a non-visual class that encapsulates presentation logic
View models can be debugged independently of views and models
View models typically do not reference views directly
The view model implements the properties and commands that the view uses for data binding.
The view model notifies you of a change in view state by changing reminder events: INotifyPropertyChanged and INotifyCollectionChanged
View model coordinates the interaction between view and model
The view model can define the logical state that the view presents to the user.
Model class
Model encapsulates business logic and data in the MVVM schema. Business logic defines, like all program logic related to retrieval and program data management, to ensure that all business rules that ensure the persistence and effectiveness of data are applied. * reuse of code, the model cannot contain any specific situations, specific user tasks and program logic.
A typical model presents a client domain model for the program, and the model may also contain code that supports data access and caching, even if a separate database or service is used. Model and data room layering is usually generated as data access or whining structures, such as ADO.NET corpse mines, WCF data services, or WCF RIA services.
The model layer enables you to easily bind views. This usually means that it supports notification of property and collection changes through INotifyPropertyChanged and INotifyCollectionChanged. The model class that presents the collection of objects is typically derived from the ObservableCollection class, which provides an implementation of the INotifyCollectionChanged interface.
The model can also support data validation and error reporting through the IDataErrorInfo interface. These interfaces allow WPF data binding to be notified when the value changes, thus updating the interface. Models usually play the following key roles:
Model classes are invisible classes that encapsulate program data
Model classes do not directly apply views or view model classes
Model classes do not depend on how they are implemented
Model classes typically provide property and collection change events through the INotifyPropertyChanged/INotifyCollectionChanged interface.
The model class typically inherits from the ObservableCollection class
The model class is typically passed through IDataErrorInfo/INotifyDataErrorInfo. Provide data validation and error reporting
Model classes are typically used with services that encapsulate data access.
After reading the above, do you know how to understand the NET MVVM design pattern? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.