FunctionZero.Maui.MvvmZero
2.0.0-pre1
See the version list below for details.
dotnet add package FunctionZero.Maui.MvvmZero --version 2.0.0-pre1
NuGet\Install-Package FunctionZero.Maui.MvvmZero -Version 2.0.0-pre1
<PackageReference Include="FunctionZero.Maui.MvvmZero" Version="2.0.0-pre1" />
paket add FunctionZero.Maui.MvvmZero --version 2.0.0-pre1
#r "nuget: FunctionZero.Maui.MvvmZero, 2.0.0-pre1"
// Install FunctionZero.Maui.MvvmZero as a Cake Addin #addin nuget:?package=FunctionZero.Maui.MvvmZero&version=2.0.0-pre1&prerelease // Install FunctionZero.Maui.MvvmZero as a Cake Tool #tool nuget:?package=FunctionZero.Maui.MvvmZero&version=2.0.0-pre1&prerelease
FunctionZero.Maui.MvvmZero
Major Improvements
This is a pre-release. All functionality for building and navigating pages is complete. Some interfaces may not be final.
This is an evolution of MvvmZero for Xamarin
Overview
This library provides an exceptionally lightweight and easy to use framework for building cross-platform MAUI apps using the MVVM design pattern.
- No naming conventions are enforced, so you can use your own, or none at all.
- There is a recommended naming convention and folder structure for the less maverick amongst us.
- The mapping of ViewModels to Views does not have to be 1:1
- can be context-sensitive, or overridden at any time.
- Navigation by ViewModel is recommended and has first-class support.
- Page navigation is also supported, as is mix and match MAUI navigation and MvvmZero page or ViewModel navigation without things breaking!
- Special support for Flyout and any derivatives.
- Special support for IMultiPage<Page> (e.g. TabbedPage) and any derivatives.
- ViewModel initialisation is typesafe, optional, and asynchronous if you want it to be.
Ethos
MvvmZero
is there to guide the way, not get in the way.
If you understand the MVVM pattern and the UI stack for MAUI, the aim is for MvvmZero to be intuitive, and to remain so if
you go off the beaten track to do things your own way.
QuickStart:
Configure MauiProgram.cs
and launch in App.xaml.cs
MauiProgram.cs
In MauiProgram.cs
configure MvvmZero
and your container.
namespace SampleTabbedApp
{
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
*******************************
*** CONFIGURE MVVMZERO HERE ***
*******************************
)
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
#if DEBUG
builder.Logging.AddDebug();
#endif
********************************
*** CONFIGURE CONTAINER HERE ***
********************************
return builder.Build();
}
}
}
Configure MvvmZero
.UseMauiApp<App>()
.UseMvvmZero(
serviceBuilder =>
{
// Configure MvvmZero ...
serviceBuilder
.MapVmToView<ReadyPageVm, ReadyPage>() // Visualise a ReadyPageVm in a ReadyPage
.MapVmToView<SteadyPageVm, SteadyPage>()
.MapVmToView<GoPageVm, GoPage>();
...
}
Configure your container
Register all your Pages and ViewModels in the Container.
MvvmZero
registers IPageService
and NavigationPage
in the container for you.
Unless you override the TypeFactory
everything else MvvmZero
is asked to instantiate must
be registered in the container.
This includes FlyoutPage
and TabbedPage
if you use them.
builder.Services
// The root page is supplied by the container!
// AdaptedTabbedPage Because https://github.com/dotnet/maui/issues/14572
.AddSingleton<MultiPage<Page>, AdaptedTabbedPage>()
.AddSingleton<ReadyPage>()
.AddSingleton<SteadyPage>()
.AddSingleton<GoPage>()
.AddSingleton<ReadyPageVm>()
.AddSingleton<SteadyPageVm>()
.AddSingleton<GoPageVm>()
// TestPage/Vm are transient because there can be more than one on any navigation stack at any time.
.AddTransient<TestPage>()
.AddTransient<TestPageVm>()
;
App.xaml.cs
In App.xaml.cs
public partial class App : Application
{
public App(IPageServiceZero pageService)
{
InitializeComponent();
pageService.Init(this); // Required!
// This app has a TabbedPage containing 3 tabs at the root.
MainPage = pageService.GetMultiPage(VmInitializer, typeof(ReadyPageVm), typeof(SteadyPageVm), typeof(GoPageVm));
}
private bool VmInitializer(object viewModel)
{
if (viewModel is ReadyPageVm)
return false; // Do not wrap the ReadyPage in a NavigationPage.
return true;
}
}
Samples
There are 3 sample applications in the repo. They are what I use for development, so they're not pretty.
- SampleApp. Has a root navigation page and pages can be pushed / popped.
- SampleFlyoutApp. This has a flyout managing multiple navigation pages, one of which is a TabbedPage.
- SampleTabbedApp. This has a TabbedPage managing 3 Tabs, 2 of which are navigation pages.
For each sample application, look at:
- MauiProgram.cs for registrations.
- App.xaml.cs to get things off the ground.
Workarounds
Currently the samples use AdaptedTabbedPage
because TabbedPageBug
and AdaptedFlyoutPage
because AdaptedPageBug
If you target WinUI, you'll want to make any pushed pages Transient until this bug is fixed.
The rest is basically the same as found in the Xamarin Turorial
Is anybody out there?
Full documentation and better samples are on the way! Give me encouragement by starring the repo!
Whilst you're here, take a look at Maui.zBind and tell all your friends. It's already included in MvvmZero
.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0-android33.0 is compatible. net7.0-ios16.1 is compatible. net7.0-maccatalyst16.1 is compatible. net7.0-windows10.0.19041 is compatible. net8.0-android was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-windows was computed. |
-
net7.0-android33.0
- FunctionZero.CommandZero (>= 1.1.0)
- FunctionZero.Maui.Controls (>= 2.3.1.7)
- FunctionZero.Maui.zBind (>= 1.1.0)
-
net7.0-ios16.1
- FunctionZero.CommandZero (>= 1.1.0)
- FunctionZero.Maui.Controls (>= 2.3.1.7)
- FunctionZero.Maui.zBind (>= 1.1.0)
-
net7.0-maccatalyst16.1
- FunctionZero.CommandZero (>= 1.1.0)
- FunctionZero.Maui.Controls (>= 2.3.1.7)
- FunctionZero.Maui.zBind (>= 1.1.0)
-
net7.0-windows10.0.19041
- FunctionZero.CommandZero (>= 1.1.0)
- FunctionZero.Maui.Controls (>= 2.3.1.7)
- FunctionZero.Maui.zBind (>= 1.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
8.0.3 | 153 | 3/31/2024 | |
8.0.2 | 101 | 3/31/2024 | |
8.0.1 | 244 | 1/7/2024 | |
8.0.0 | 181 | 10/21/2023 | |
8.0.0-pre1 | 76 | 10/14/2023 | |
2.0.4.2-pre1 | 149 | 8/26/2023 | |
2.0.4.1 | 196 | 8/20/2023 | |
2.0.4 | 149 | 8/19/2023 | |
2.0.3 | 237 | 7/8/2023 | |
2.0.2 | 153 | 6/27/2023 | |
2.0.1 | 148 | 6/26/2023 | |
2.0.0 | 174 | 4/23/2023 | |
2.0.0-pre1 | 131 | 4/22/2023 | |
1.1.2 | 237 | 3/29/2023 | |
1.1.1 | 225 | 3/21/2023 | |
1.1.0 | 239 | 3/18/2023 | |
1.0.2 | 222 | 3/16/2023 | |
1.0.1 | 214 | 3/15/2023 | |
1.0.0 | 237 | 3/15/2023 |
This is a preview. All functionality for building and navigating pages is present. Interfaces may not be final. (any changes will be a simple refactor)