FunctionZero
  • Libraries
    • Maui.MvvmZero
      • Overview
      • Quickstart
      • Walkthrough
        • Create your application
        • Create your ContentPages
        • Create your ViewModels
        • Register your new content
        • Launching our app!
        • Adding Navigation
        • Summary
      • Recommended naming conventions
      • Configuring your root Page
        • Root ContentPage
        • Root NavigationPage
        • Root TabbedPage
        • Root FlyoutPage
      • A note on Singleton vs Transient
      • Recommended base classes for PageViewModels and ViewModels
    • Maui.Controls
      • ExpanderZero
      • FocusScrollZero
      • LabelZero
      • ListViewZero
      • MaskZero
      • MultiViewZero
      • TreeViewZero
    • CommandZero
    • Maui.BindZero
      • Quickstart
      • z:Bind
      • Examples
      • The Great Escape
      • Casting
      • Short Circuit
      • Errors
      • Aliases
      • Value types and Reference types
      • z:Function
      • z:TapTrigger
      • z:EdgeTrigger
      • z:Latch
      • Advanced Usage - Functions, aliases and operator-overloads
    • AnimationZero
    • LocalisationZero
Powered by GitBook
On this page
  1. Libraries
  2. Maui.MvvmZero
  3. Walkthrough

Create your ViewModels

First we're going to create a couple of base classes for our PageViewModels and ViewModels. It's not necessary, but it makes life much easier if we later on want to insert our own base class functionality. If you do not wish to do this then you can simply derive your ViewModel classes directly from the library implementations (or not - MvvmZero does not require you use its base classes)

In your Mvvm/PageViewModels folder, add the following abstract class:

using FunctionZero.Maui.MvvmZero;

namespace MvvmZeroTutorial.Mvvm.PageViewModels
{
    public abstract class BasePageVm : MvvmZeroBasePageVm
    {
    }
}

Similarly, in your Mvvm/ViewModels folder, add the following abstract class:

using FunctionZero.Maui.MvvmZero;

namespace MvvmZeroTutorial.Mvvm.ViewModels
{
    public abstract class BaseVm : MvvmZeroBaseVm
    {
    }
}

Now we want to create a ViewModel for each of the ContentPages. In the Mvvm/PageViewModels folder, add ReadyPageVm

Make the class public and derive from our base implementation for a PageViewModel:

namespace MvvmZeroTutorial.Mvvm.PageViewModels
{
    public class ReadyPageVm : BasePageVm
    {
    }
}

Repeat the process for SteadyPageVm, GoPageVm and DetailPageVm

And here we are:

Next we're going to register our Pages and ViewModels so they can be presented.

PreviousCreate your ContentPagesNextRegister your new content

Last updated 1 year ago

Adding our first ViewModel
4 ViewModels added to the project