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 !!!