loading experience

.NET MAUI

MAUI Blazor Hybrid: the same interface on the web and in apps

Razor components shared between website and native apps, with full access to device APIs.

MAUI Blazor Hybrid: the same interface on the web and in apps

With Blazor Hybrid, Razor components run directly inside the native .NET MAUI app and are displayed through an embedded web control. There is no server and no WebAssembly: the C# code runs on the device, with full access to its APIs.

The same interface code serves the web and the native apps.
The same interface code serves the web and the native apps.

Why choose it

  • Reuse: the same pages and components serve the website and the phone and desktop apps.
  • Web skills: HTML and CSS for the interface, C# for the logic.
  • Native features: camera, files, notifications and sensors remain available.

The recommended structure

The "MAUI Blazor Hybrid and Web App" template creates three projects: a shared Razor library with the components, the MAUI app and the web application. Platform-dependent features are defined as interfaces in the shared library and implemented separately.

// shared library
public interface IFormFactor
{
    string Device { get; }
}

// MAUI app
public class MauiFormFactor : IFormFactor
{
    public string Device => DeviceInfo.Current.Idiom.ToString();
}

// web app
public class WebFormFactor : IFormFactor
{
    public string Device => "Web";
}
@inject IFormFactor FormFactor

<p>You are using: @FormFactor.Device</p>

Things to know

  • The look is the web's, not that of native controls: design for small screens carefully.
  • The system's embedded web control (WebView2 on Windows, WKWebView on iOS and macOS, WebView on Android) affects compatibility and performance.
  • You can mix native XAML pages and Blazor pages in the same app.

For teams that already have a Blazor application, it is the fastest way to reach the app stores without rewriting the interface.

Comments (0)

No comments yet.

Leave a comment