Challenge: Applying MVVM

Test yourself by applying the MVVM architectural pattern in an MAUI application.

Using the project at the end of this lesson, perform the tasks highlighted in the problem statement section.

Problem statement

We have an application that adds two numbers and displays them in a label. The challenge consists of the following tasks:

  • Binding the ViewModel to the View.

  • Expanding the ViewModel.

Binding the ViewModel to the View

The project at the end of this lesson contains a ViewModel object called SumViewModel, but it's not currently linked to the main page of the application. You need to bind this ViewModel to the main page. You also need to bind the FirstNumber property of the ViewModel to the editable text box on the page.

Expanding the ViewModel

In the current setup, the code-behind is performing some actions that should be outsourced to the ViewModel. You'll need to remove this logic from the code-behind class and move it to the ViewModel. The requirements are as follows:

  • The ViewModel class stores the second number.

  • The ViewModel class tracks the sum of the two numbers.

  • Both entries and the label are bound to the ViewModel fields.

If you get stuck at any point, you can access the hint below:

Get hands-on with 1200+ tech skills courses.