.netblazorasp.net-blazormaui

Can you develop a webpage using .NET MAUI and blazor and target the web, ios, android and windows?


I have recently read up on .NET MAUI but I am confused about its purpose with Blazor.

Can you develop a webpage using .NET MAUI and blazor and target the web, ios, android and windows?

For example develop the web page effectively to also work as an app on any other devices, but in the browser work the normal Blazor way (i.e use WASM)?


Solution

  • In .NET MAUI a BlazorWebView component is added, which can run full Blazor code, including css and the JavaScript interop (so it can even run all kinds of JavaScript components).

    Because the way you define pages and the wwwroot can be exactly the same in a .NET MAUI Blazor project as in a Blazor WASM project, you can share your Blazor pages, wwwroot, code etc.: Put the same code both in your Blazor WASM project and in your .NET MAUI Blazor project. You can also add and use your Blazor class libraries. This way, you can run exactly the same code in a web browser (Blazor WASM) AND in a native iOS/Android/Windows/Mac app (.NET MAUI).

    Extra bonus: when running on .NET MAUI you run native, so you can access all native components/hardware, add push notifications etc. from Blazor, which you don't have access to from a Web App.

    See the Introduction to .NET MAUI Blazor video for a clear explanation.

    In the .NET MAUI app, the BlazorWebView is a component, so you can combine it with XAML code if you want to.

    However, the opposite is not true, you can NOT run a XAML UI in a Blazor WASM web application.