Search code examples
mauimaui-blazor

how to use a BlazorWebView as component in Maui App


I am building an app and the app including menu etc.. is all in xaml,however I would like to use a BlazorWebView in one of the pages.

The app was not created using ".Net Maui Blazor app" but using ".NET MAUI App"

  • Is there a template somewhere for this scenario?
  • What do I need to add to have a blazorWebView in one of the pages?

Many thanks


Solution

  • The BlazorWebView's name space is Microsoft.AspNetCore.Components.WebView.Maui.

    So first of all is installing this nuget package in your project. And you can use different versions of it according your project.(I used the version 6.0.540 and my project is .net 6.0).

    And then you need to change the project's Sdk from Microsoft.NET.Sdk to Microsoft.NET.Sdk.Razor by the first line code in the project.csproj file. This will fix the errors appear after you adding this nuget package into your project.

    After this, I can delare a BlazorWebView in the maui project's content page. Both in the xaml and the code behind.

    Finally, it seem using the maui control in the maui blazor project is easier than using the blazor control in the maui project. You can also try to move your code into a maui blazor app.