Skip to content

.NET MAUI Toolkit is a set of fluent helper methods and classes to simplify working with .NET MAUI. Made available as NuGet packages.

License

Notifications You must be signed in to change notification settings

egvijayanand/dotnet-maui-toolkit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Join me on Developer Thoughts, an exclusive blog for .NET MAUI and Blazor, for articles on working with these toolkits and much more.

VijayAnand.Toolkit.Markup

VijayAnand.Toolkit.Markup is a shared class library NuGet package with a set of fluent helper methods and classes for Xamarin.Forms / .NET MAUI to facilitate rapid UI development and better reuse in C#.

VijayAnand.Toolkit.Markup .NET 6 .NET 7 .NET 8 .NET 9
Stable .NET 6 .NET 7 .NET 8 -
Preview - - - .NET 9

This extends the features of the official C# Markup NuGet package from Microsoft.

netstandard2.0 library targets Xamarin.Forms 5 and is dependent on the Xamarin.CommunityToolkit.Markup package.

Whereas the net6.0, net7.0, net8.0, and net9.0 library targets .NET MAUI and is dependent on the CommunityToolkit.Maui.Markup package. Note this is NOT a MauiCompat package.

VijayAnand.MauiToolkit.Core

This is a toolkit with a set of abstractions to simplify working with .NET MAUI and Blazor.

VijayAnand.MauiToolkit.Core .NET 6 .NET 7 .NET 8
Stable .NET 6 .NET 7 .NET 8

The objective is to ease the development of the Razor Class Library (RCL) so that it can be shared with all Blazor targets (.NET MAUI, Server, WebAssembly, Windows Forms, and WPF).

And .NET MAUI targets Android, iOS, macOS (via Mac Catalyst), Tizen, and Windows (via WinUI 3).

To start with define the following abstractions:

  • Dialogs - IDialogService
  • Navigation - INavigationService
  • Share - IShareService
  • Theme - IThemeService

A Model class for UserToken and frequently used Constants for OAuth / OIDC authentication.

VijayAnand.MauiToolkit

This is a toolkit with a set of helper methods and classes to simplify working with .NET MAUI and Blazor.

VijayAnand.MauiToolkit .NET 6 .NET 7 .NET 8
Stable .NET 6 .NET 7 .NET 8

It depends on VijayAnand.MauiToolkit.Core NuGet package.

To start with, implement the concrete definition of the abstractions defined in the Core package:

  • Dialogs - DialogService (works with MainPage or Shell definition)
    • Additional abstraction specific to .NET MAUI with FlowDirection
  • Navigation - NavigationService (based on Shell Navigation pattern)
  • Share - ShareService (based on Maui Essentials)
  • Theme - ThemeService (based on UserAppTheme property)

And includes a set of Markup extension methods for rapid application development with C#.

These fluent APIs are made available in the VijayAnand.MauiToolkit.Markup namespace.

Provides an extension method to register these services in .NET MAUI host builder startup:

UseVijayAnandMauiToolkit()

Now it's possible to selectively register the services required into the DI container.

Added a configuration parameter of Enum type ServiceRegistrations (Flags-attributed) to the UseVijayAnandMauiToolkit() method.

To illustrate with a sample, if only interested in NavigationService:

Then, invoke UseVijayAnandMauiToolkit(ServiceRegistrations.Navigation).

And if DialogService is required along with NavigationService:

Then, invoke UseVijayAnandMauiToolkit(ServiceRegistrations.Dialogs | ServiceRegistrations.Navigation).

By default, the default value of the configuration parameter is set to ServiceRegistrations.All.

Usage:

public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();
        builder.UseMauiApp<App>()
               .UseVijayAnandMauiToolkit(); // Implicit value of ServiceRegistrations.All passed as a configuration parameter
        return builder.Build();
    }
}

VijayAnand.MauiToolkit.Pro

This is a toolkit with a set of helper methods and classes to simplify working with .NET MAUI and Blazor.

VijayAnand.MauiToolkit.Pro .NET 6 .NET 7 .NET 8
Stable .NET 6 .NET 7 .NET 8

It depends on the following NuGet packages:

To start with implements the concrete definition PopupDialogService for the IDialogService abstraction defined in the Core package and IMauiDialogService abstraction defined in the Regular package with the Popup type from the CommunityToolkit.Maui NuGet package.

Provides an extension method to register this service in .NET MAUI host builder startup:

UseVijayAnandMauiToolkitPro()

By default, the default value of the configuration parameter is set to ServiceRegistrations.All.

Usage:

public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();
        builder.UseMauiApp<App>()
               .UseMauiCommunityToolkit()
               .UseVijayAnandMauiToolkitPro(); // Implicit value of ServiceRegistrations.All passed as configuration parameter

        return builder.Build();
    }
}

VijayAnand.MauiBlazor.Markup

This toolkit is a set of fluent helper methods and classes to simplify working with .NET MAUI Blazor in C#.

This toolkit depends on Microsoft.AspNetCore.Components.WebView.Maui NuGet package.

VijayAnand.MauiBlazor.Markup .NET 6 .NET 7 .NET 8 .NET 9
Stable .NET 6 .NET 7 .NET 8 -
Preview - - - .NET 9

The most useful method will be Configure, which can be invoked on an instance of a BlazorWebView and its derivatives, and it simplifies the initialization of BlazorWebView into a single fluent method call as shown in the below sample.

Note: Gateway is a Razor component and assumes it can receive a parameter named Foo as described in the sample underneath.

namespace MyApp;

public class HomePage : ContentPage
{
    public HomePage()
    {
        // A BlazorWebView can manage multiple RootComponents, to achieve this, define another Tuple with values of that component
        // The method and Tuple parameter names are shown for clarity and it's optional
        // Blazor component can have initialization parameters, which can be supplied through parameters, a dictionary of keyValues
        // where the key is of type string and value is of type object

        // Without initialization parameters
        Content = new BlazorWebView().Configure(hostPage: "wwwroot/index.html", (selector: "#app", componentType: typeof(Gateway), parameters: null));

        // With optional initialization parameters
        Content = new BlazorWebView().Configure(hostPage: "wwwroot/index.html", (selector: "#app", componentType: typeof(Gateway), parameters: new Dictionary<string, object?> { [nameof(Gateway.Foo)] = "Bar" }));

        // In a simplified form - Real intended usage
        // Without initialization parameters
        Content = new BlazorWebView().Configure("wwwroot/index.html", ("#app", typeof(Gateway), null));
        // Much more simplified, assuming hostPage is wwwroot/index.html and selector as #app
        Content = new BlazorWebView().Configure(typeof(Gateway));

        // With StartPath property introduced in .NET 8 or later, overloaded Configure method
        // Assuming search is the page with which the app is intended to start
        Content = new BlazorWebView().Configure("wwwroot/index.html", "/search", ("#app", typeof(Gateway), null));
        // Much more simplified version, assuming hostPage is wwwroot/index.html and selector as #app
        Content = new BlazorWebView().Configure(typeof(Gateway), "/search");

        // With optional initialization parameters
        Content = new BlazorWebView().Configure("wwwroot/index.html", ("#app", typeof(Gateway), new Dictionary<string, object?> { [nameof(Gateway.Foo)] = "Bar" }));
    }
}
@page "/gateway"

<h2>I'm a razor component named Gateway and I can receive a parameter named Foo.</h2>

@code {
    [Parameter]
    public string Foo { get; set; }
}