TinyMvvm for .NET MAUI – Preview

TinyMvvm is an open-source project I started back in 2017 primary to be used in my own apps, both private projects, and client projects. I recently released 3.0 that has been in preview for a long time and I used it in apps I have shipped to the app stores. After the 3.0 release, I have focused on bringing TinyMvvm to .NET MAUI and now there is a public preview available.

Instead of migrating the TinyMvvm.Forms project to .NET MAUI I created a new .NET 6 project with the name TinyMvvm.Maui. That means that both will live side-by-side The first thing I did there was to copy all the code from the Forms project and migrate it to MAUI, .NET 6, and C#10. That means that I am using the MAUI namespaces instead of the Xamarin.Forms namespaced, I am using global usings and file-scoped namespaces.

The big change compared to the Forms version of TinyMvvm is how you initialized it. The only thing you need to do now is to use the extension method UseTinyMvvm() on the MauiAppBuilder and initialize the resolver as shown below. If your ViewModels or View are in another assembly you can specify it as an argument to UseTinyMvvm(Assembly viewAssembly, Assembly, viewModelAssembly). If you don't use Shell navigation you can pass an argument to use classic navigation. UseTinyMvvm(bool useClassicNavigation).

The next step is to analyze how I can optimize TinyMvvm for .NET MAUI.

public static MauiApp CreateMauiApp()
            var builder = MauiApp.CreateBuilder();
                .ConfigureFonts(fonts =>
                    fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");

            var app = builder.Build();

            Resolver.SetResolver(new ServiceProviderResolver(app.Services));

            return app;

You can install the package from NuGet.

To find out more about how to use TinyMvvm you can read the documentation for Xamarin.Forms. Before the stable release of this package, the documentation will be fully updated with how to use it with .NET MAUI.

If you have feedback please create an issue on GitHub.

.NET MAUI Preview on Mac

Visual Studio for Mac is not supporting the current .NET preview. But that doesn't mean that you cannot start to play with MAUI. But you have to use the terminal and for example Visual Studio Code.

Install .NET MAUI

If you do not have installed the preview yet, I recommend you to do that with the Maui Check Tool, https://github.com/Redth/dotnet-maui-check. That will guide you through the process and make sure that you have everything you need install.

Create a project

To create a new project, just use the dotnet new command as with all .NET Core/.NET 5 projects.

dotnet new maui -n MyFirstMauiApp

or this for a MAUI Blazor (Hybrid app) project.

dotnet new maui-blazor -n MyFirstMauiApp

If you want to take a look at a sample app, you may have seen the Weather Twenty One app by David Ortinau. That project is open-source and a good app to sample to start with if you want to explore MAUI, https://github.com/davidortinau/WeatherTwentyOne.

Run a .NET MAUI app

When you want to run an MAUI app from a command, you need to specify what framework you want to use, for example, .NET 6 iOS.

# iOS
dotnet build {YourProjectName} -t:Run -f net6.0-ios
# MacOS
dotnet build {YourProjectName} -t:Run -f net6.0-maccatalyst
# Android
dotnet build {YourProjectName} -t:Run -f net6.0-android
Weather Twenty One app running on Mac Catalyst and iOS simulator

Weather Twenty One app running on Mac Catalyst and iOS simulator

Run on a specific iOS simulator

When you started the iOS project, it probary started on an iPad simulator. If you want to use another simulator you need to set the UDID of the simulator in the command like this:

dotnet build {YourProjectName} -t:Run -f net6.0-ios /p:_DeviceName=:v2:udid={DeviceUDID}

To get all UDID:s run the following command:

xcrun simctl list

Run on an Android emulator

To run it on an Android emulator, just start the emulator before you start the app.

Weather Twenty One app running on Android emulator

Weather Twenty One app running on Android emulator

More resources

Official MAUI Sample repo - https://github.com/dotnet/maui-samples
MAUI source code - https://github.com/dotnet/maui
Announcing .NET MAUI Preview 4 - https://devblogs.microsoft.com/dotnet/announcing-net-maui-preview-4