XAML Integration

This page describes how is possible to integrate MauiReactor components in a classic XAML-C# MAUI application

Sometimes, you may want to adopt the MVU approach only for a portion of the application. For example, when you have already developed an XAML-based app and are not ready to completely rewrite it using a different framework like MauiReactor.

XAML integration in MauiReactor allows you to run a MauiReactor component inside a standard MAUI page or view. You can even use a MauiReactor component for an entire page while the rest of the app uses a classic MVVM approach.

1) Let's start by adding the MauiReactor Nuget package to the project (pick the latest version):

dotnet add package Reactor.Maui

2) Configure the application to use MauiReactor:

var builder = MauiApp.CreateBuilder();
builder
    .UseMauiApp<App>()
    .UseMauiReactor() //<--- ADD THIS LINE
    .ConfigureFonts(fonts =>
    {
        fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
        fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
    });

Host a MauiReactor component

To host a MauiReactor component on your page, please use the ComponenHost class like it's shown in the following snippet code:

In line 4, you have to specify the MauiReactor namespace and assembly containing the ComponentHost class.

In lines 33 and 34, we're going to create an instance of the control ComponentHost passing the Counter component type as a parameter: the ComponentHost class will instantiate and run the component.

Of course, the same can be done in code:

Host a MauiReactor page

Another way to integrate a MauiReactor component is to navigate to another page passing a component as its root using the overload of the Navigation class Navigation.PushAsync<Component-Type>()

Where ChildPage is defined as:

The same works with the Shell as well. You need to register the route using the static method Routing.RegisterRoute and navigate to it with the usual Shell.Current.GoToAsync call:

Last updated

Was this helpful?