Skip to content

9.4. .NET MAUI Integration

Wire a ComponentVM<M> to a .NET MAUI page (desktop and mobile XAML) through the same INotifyPropertyChanged adapter as WPF.

9.4.1. Reactivity Primitive

MAUI binds through INotifyPropertyChanged and ICommand, as WPF does. The shared rules are in WPF: Reactivity primitive.

9.4.2. Mapping

The shared XAML mapping applies. MAUI adds these rows:

MAUI VMx
ObservableCollection<T> ServicedObservableCollection<T> or wrap an ObservableList<T>
MainThread.BeginInvokeOnMainThread SynchronizationContextScheduler created on the UI thread (host)
page BindingContext BindableScreen<M>, which holds the BindableVm<M> adapter

9.4.3. Adapter Skeleton

MAUI uses the XAML adapter BindableVm<M> unchanged, with the same four rules. XamlRecipeTests.cs executes the adapter on test schedulers. CI has no MAUI host, so no MAUI version is tested, and the BindingContext statement below runs against a stand-in page.

Create the adapter on the main thread, for example in the page constructor, wrap it in a BindableScreen<Note> with the Save command, and set that as the page's BindingContext:

var note = new BindableVm<Note>(
    vm, new SynchronizationContextScheduler(SynchronizationContext.Current!));
BindingContext = new BindableScreen<Note>(note, save);

9.4.4. Fuller Example

There is no MAUI Notes-Showcase. For copyable starting points, see the WPF TodoApp in wpf.md and the Avalonia flagship in avalonia.md. Microsoft's MAUI MVVM docs cover the framework-side mechanics.