Mvvm Design Mode

Source: Internet
Author: User

Here we will only introduce the theoretical part. Here is a simple example of mvvm. Here is an example I wrote, which is very simple.

1. mvvm: Model-View-view Model)

The mvvm design mode is based on the MVC structure that separates UI from logic.

View: interface layer;

Viewmodel: it is the abstract of the view and passes the view command to the model;

Mode: data access layer

2. The mvvm architecture in Silverlight or WPF provides the following benefits:

1. projects can be tested more easily to execute unit tests.

2. Completely separate the UI and business design. View and unittest are only two different forms of consumers of viewmodel.

3. It helps us differentiate and what are UI operations and what are business operations, rather than mixing them all in codebehind.

3. Role of viewmodel:

Viewmodel is the most important part in the mvvm architecture. viewmodel contains attributes, commands, methods, events, attribute verification, and other logic.

Viewmodel attributes: The attribute of viewmodel is the source of View data. These attributes can be composed of three parts:

Part is the copy attribute of the model.

The other part is used to control the UI status.

The third part is the parameters of some methods.

Viewmodel command: The command in viewmodel is used to accept the user input of the view and process it accordingly. We can also implement the same functions through methods.

Viewmodel events: Events in viewmodel are mainly used to notify the view to perform corresponding UI changes.

Viewmodel Method: Some events do not directly provide command calls, such as custom events. At this time, we can call the method in viewmodel through callmethodaction to complete the corresponding operation.

References: http://msdn.microsoft.com/zh-cn/magazine/dd419663.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.