How to add a Blazor Page to an existing .NET MAUI application

Viewed 38

If you have an existing .NET MAUI application/project (Xaml) and want to add a Blazor Page to it, what steps would be needed to get it working? Have tried using the steps described here but there seem to be more that is needed.

https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/blazorwebview

While the main question is about adding Blazor pages to an existing MAUI project, for simplicity, let's assume you have a just created a new .NET MAUI project in VS2022 and would like to add the typical Counter Blazor page that is generated by most VS2022 templates and get it up an running.

@page "/counter"

<h1>Counter</h1>

<p role="status">Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
    private int currentCount = 0;

    private void IncrementCount()
    {
        currentCount++;
    }
}

As this is an existing project, just using the .NET MAUI Blazor template most likely isn't an option here unless you move everything not Blazor over to the new project.

Thanks.

0 Answers
Related