Developing Hybrid App with Blazor WASM and .NET MAUI
Blazor
29 Articles
In this article, let's learn about developing Hybrid App
using Blazor WASM and MAUI.
Note: If you have not done so already, I recommend you read the article on Developing Hybrid App with Blazor WASM and .NET MAUI.
Table of Contents
Introduction
So far we have learned how to build and run blazor web app. In a Blazor Hybrid app, Razor components run
natively
on the device. Components render to an embedded Web View control
through a local interop channel
. Components don't run in the browser, and WebAssembly isn't involved.
Razor components load and execute code quickly, and components have full access to the native capabilitie
of the
device through the .NET platform. Component styles rendered in a Web View are platform dependent
and may require
you to account for rendering differences across platforms using custom stylesheets.
Join me on a journey of building your first hybrid applications across iOS, Android, Mac, Windows, and web with ASP.NET Core, Blazor,
Blazor Hybrid, and .NET MAUI
. Learn how to use Blazor Hybrid to blend desktop and mobile native client frameworks with .NET and Blazor.
Converting Blazor WASM to MAUI Hybrid App
Let's take our I Love DotNet Blazor WASM
app and convert it to a MAUI Hybrid
app. The steps we need to follow are:
Create a web assembly app. In our case we already have our I Love Dotnet Blazor Wasm app.
- Create a
common razor class library
. Move the pages/components/assets
to common razor class library.Create MAUI Blazor Hybrid
Project.Reuse the
common razor class library
inMAUI
andBlazor
.-
Now we need configure
MauiProgram.cs
andregister the dependencies
as we have done in Blazor WasmProgram.cs
Make sure to configureenvironment
additionally inMauiProgram.cs
. -
We need to configure the
Routes.razor
component inMaui
App same as we have done inBlazor Wasm
App. -
We need to configure the
index.html
inMaui
App same as we have done inBlazor Wasm
App. -
To make use of
native platform features
inrazor class library
, we need to add<UseMauiEssentials>true</UseMauiEssentials>
in the.csproj
file and add reference to NugetMicrosoft.Maui.Essentials
. -
Make sure you point to
index.html
fromwwwroot
ofcommon razor class library
inMainPage.xaml
of Maui project. - Thats it. Now we can run the app and see the same Blazor Wasm app running as a MAUI Hybrid app.
MacOS
iOS
Andriod
Windows
Web
Summary
In this article, we learnt about developing Hybrid App using Blazor WASM and MAUI
. We also learnt about the steps
to convert Blazor WASM
to MAUI Hybrid
App and gone through the steps we
need to take to ensure native platform features
are available in the razor class library. Boom we now have a
single codebase running in multiple platforms and devices
.