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.
Using MauiReactor (i.e., MVU) for the entire application remains recommended.
Consider this feature if you are facing the following scenarios:
1) You have completed the development of a standard MAUI application or are in an advanced stage of the process where moving to MauiReactor is not feasible, but you're interested in adopting MauiReactor in the future
2) You may want to adopt/experiment with the MVU approach for some specific portion or page of the UI
Do not mix MVU and MVVM code/approaches but use the dependency inject to share services.
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:
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?