Skip to content
Shiny PlatformShiny Platform
.NET MAUI on the WebRun your MAUI app in the browser on WebAssembly - real DOM elements, no Blazor. Try the web sample and the .NET MAUI GalleryGet started

Uno Platform

The Uno Platform is an Open-source platform for building single codebase native mobile, web, desktop, and embedded apps quickly.

With Uno Platform + Mediator, your pages and view models can handle events without being registered in dependency injection, handlers marked [MainThread] run on the UI thread, and you get all of the offline, persistent cache, and other app-building middleware.

Visit their website and documentation for more details.

  1. Install NuGet package Shiny.Mediator.Uno to your project.
  2. In your App.xaml.cs file, register the mediator on the Uno application builder:
    protected override async void OnLaunched(LaunchActivatedEventArgs args)
    {
    var builder = this.CreateBuilder(args)
    .AddShinyMediator(cfg => cfg.AddUnoPersistentCache())
    .Configure(host => host
    // your other host configuration
    );
    MainWindow = builder.Window;
    Host = await builder.NavigateAsync<Shell>();
    }
    AddShinyMediator on the application builder also hands builder.Window to the mediator. The window is needed for the event collector, error dialogs, and [MainThread].
  3. Start making calls to the mediator as you normally would.

If you build your own service collection, pass your window to UseUno:

services.AddShinyMediator(cfg => cfg.UseUno(MainWindow));

If you only have an IHostBuilder, host.AddShinyMediator() registers everything, but no window is tracked. Add it yourself once it exists:

Host.Services.GetRequiredService<UnoWindowTracker>().Add(MainWindow);

Use the same call for any secondary window that should take part. A window stops being tracked when it closes.

UseUno installs the Uno event collector. When an event is published, the collector walks the visual tree of every tracked window, including open popups, on the UI thread. Any FrameworkElement, or its DataContext, that implements IEventHandler<TEvent> takes part in the publish. A view model shared by many elements is called once.

public partial class MainViewModel : ObservableObject, IEventHandler<OrderShipped>
{
[MainThread]
public Task Handle(OrderShipped @event, IMediatorContext context, CancellationToken ct)
{
this.Status = $"Order {@event.OrderId} shipped";
return Task.CompletedTask;
}
}

A publish from a background thread waits up to 5 seconds (UnoEventCollector.UiThreadTimeout) for the UI thread to collect handlers. If the UI thread is blocked, view handlers are skipped and a warning is logged.

The Mediator Uno Platform extension installs default middleware, which you can opt out of. To skip it, pass false for includeStandardMiddleware (UseUno(false) or AddShinyMediator(includeStandardMiddleware: false)).

Publishes a ConnectivityChanged event whenever internet availability changes (from NetworkInformation). It requires Uno.Extensions hosting, which initializes it once the host is built.

builder.AddShinyMediator(cfg => cfg.AddConnectivityBroadcaster());
public partial class MyViewModel : Shiny.Mediator.IConnectivityEventHandler
{
[MainThread]
public Task Handle(ConnectivityChanged @event, IMediatorContext context, CancellationToken ct)
{
this.IsOnline = @event.Connected;
return Task.CompletedTask;
}
}

Every infrastructure service is registered with TryAdd. To replace one, register your own before calling UseUno.

Service Default
IMainThreadDispatcher UnoMainThreadDispatcher (window DispatcherQueue)
IAlertDialogService AlertDialogService (ContentDialog)
IInternetService InternetService (NetworkInformation)
IStorageService StorageService (ApplicationData.LocalFolder)