After my internship at the company, the first technical name I came into contact with was the mvvm model, which has been around for more than half a year.ArticleI will briefly talk about my experiences in using the mvvm mode during product development.
Traditional winform and ASP. NET ApplicationsProgramIs developed based on event-driven, with ASP. for example, in actual development ,*. the ASPX page is used to render HTML ,*. aspx. CS pages are used to implement server logic. This method is convenient and quick at the early stage of development, but this high coupling leads to the complexity of maintenance in the future. Once aspx changes, aspx. CSCodeAt the same time, it needs to be changed. For example, if you replace the gridview control in aspx with the formview control, the corresponding Aspx. CS file has to be modified a lot. The reason why the mvvm mode is widely used in WPF/SL applications is that the WPF/siverlight applications are developed based on data drivers, researchers on the Internet compared mvvm mode with WPF in winform, and concluded that the development efficiency of mvvm mode is very low in a large scale in the winform project.
Mvvm mode is applied in WPF/Silverlight. View is mainly used for interface presentation, viewmodel is used for logical implementation, model is used for data construction, and the three can communicate, the most important thing is to use the powerful data binding mechanism in WPF/Silverlight to effectively associate view and viewmodel.
Although the name of the mvvm mode does not reflect the command, in actual situations, command is a crucial part of mvvm implementation. Currently, the project mainly uses the delegatecommand <t> class in the prism framework.
The advantages of using the mvvm mode in the Silverlight project are obvious:
1. For view-logic separation, it is easy to expand and maintain the original functions in the future. When the UI changes, the logic in viewmodel does not need to be changed.
2. You can simply use blend to implement simple functions without writing any code.
In the implementation process, do not just implement mvvm and mvvm, but make a trade-off based on the actual situation. In fact, because Silverlight is only a subset of WPF, its support for the mvvm mode is still lacking in some aspects:
1. It is difficult to bind enumeration types, for example, to radiobutton.
2. In silverlight4, the command attribute is only implemented for controls that inherit buttonbase. In actual use, invokecommandaction in blend4 can be used for other events.
3. You cannot pass complex objects in view and viewmodel. You can destroy view or viewmodel as a compromise, for example, the objects in childwindow and parent container are transmitted.
At present, my main research on the mvvm mode is as follows:
1. How to pass an eventargs object to viewmodel
2. Master behavior, trigger, and Action concepts to apply them to mvvm.
The mvvm mode needs to be summarized in the actual application process. Only in this way can we truly appreciate the advantages of using the mvvm mode in the program.
Learn about mvvm mode in my blog:
Using mvvm (1) In Silverlight -- Basic
Using mvvm in Silverlight (2)-improved
Use mvvm (3) in Silverlight-advanced
Using mvvm (4) in Silverlight-Walkthrough
Using mvvm (5)-command II in Silverlight
Use mvvm (6): autocompltebox asynchronous filtering in Silverlight