.NET Documentation

Blazor Hybrid

Blazor Hybrid enables you to host Blazor components in native desktop or mobile applications. This allows you to share code and UI logic between web and native platforms, leveraging your existing Blazor skills for cross-platform development.

What is Blazor Hybrid?

Blazor Hybrid apps run on .NET, but instead of a web browser rendering the UI, Blazor components are hosted within a native app using a WebView2 control (on Windows) or a similar web view component on other platforms. This provides a native look and feel while still using web technologies for UI development.

Key Benefits

Supported Platforms

Blazor Hybrid is supported on the following platforms:

Getting Started

To create a Blazor Hybrid application, you'll typically use .NET MAUI. Here's a simplified overview:

  1. Create a .NET MAUI App: Use the .NET CLI or Visual Studio to create a new .NET MAUI Blazor app.
  2. Add Blazor Components: Build your UI using Blazor components (.razor files) in the Components/Pages folder.
  3. Run your App: Deploy and run your application on your target platform.

Example Project Creation (.NET CLI):


dotnet new maui-blazor -o MyBlazorHybridApp
cd MyBlazorHybridApp
dotnet build
dotnet run
            

Hosting Models

Blazor Hybrid supports two main hosting models:

Interacting with Native APIs

Blazor Hybrid makes it easy to call native platform APIs. You can use dependency injection to inject platform-specific services provided by the hosting framework (like .NET MAUI) into your Blazor components.

Tip: Use the IConnectivity service in .NET MAUI to check network status from your Blazor components.

Common Scenarios

Further Reading