[Mvvm topic] _ mvvm example

Source: Internet
Author: User

PS: This article is from encyclopedia.

The mvvm mode is mainly used to achieve the separation of views and logic. In the example of implementation, realcommand is used at the viewmodel layer. The following is a complete example obtained on the Internet based on practices, share with you

I. The first step is in the data section, that is, the model layer is the data section, and the data source is not limited. Define the person class here, including the basic attributes used.

The following classes store the entire data list and perform simple initialization for testing.

2. At the viewmodel layer, the logic between data and interfaces is implemented. In the class, attributes and commands are included, and data is bound to the interface, command can only be bound to controls with the comman attribute. Otherwise, you must use other methods, but here you can use buttons. During command implementation, the icommand interface must be implemented when a custom command is used. In the UI interface, routecommand or routeuicommand are inherited, which has some disadvantages. Therefore, we generally use custom relaycommand, below is the basicCodeBut the definition will be changed when you want to register multiple commands.

The definition code of viewmodel is as follows:

3. The view and viewmodel layers are associated by data binding.

View-layer XAML file code:

In the background code:

So far,ProgramThe framework is basically set up, hoping to help you learn it !!!

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.