Getting Started with WinForms Blazor Application
16 Apr 20253 minutes to read
This section explains how to create and run the first WinForms Blazor App UI (.NET WinForms Blazor) app with Syncfusion® Blazor components.
What is WinForms Blazor App?
WinForms Blazor App is an app where Blazor web app
is hosted in WinForms app using BlazorWebView
control. This enable a Blazor web app to be integrated with platform features and UI controls. Also, BlazorWebView can be added to any page of WinForms Blazor app, and pointed to the root of the Blazor app. The Blazor components run natively in the .NET process and render web UI to an embedded web view control. WinForms Blazor apps can run on all the platforms supported by WinForms.
Visual Studio provides WinForms Application template to create WinForms Blazor Apps.
Prerequisites
Create a new WinForms Blazor App in Visual Studio
To create a WinForms Blazor App using Visual Studio, it is essential® to follow the comprehensive steps outlined in the Microsoft Templates documentation. Ensuring that you understand each step from the official guide will provide the foundation needed to continue with this documentation.
Install Syncfusion® Blazor Calendars and Themes NuGet in the App
Here’s an example of how to add Blazor Calendar component in the app, open the NuGet package manager in Visual Studio (Tools → NuGet Package Manager → Manage NuGet Packages for Solution), search and install Syncfusion.Blazor.Calendars and Syncfusion.Blazor.Themes. Alternatively, you can utilize the following package manager command to achieve the same.
Install-Package Syncfusion.Blazor.Calendars -Version 29.1.33
Install-Package Syncfusion.Blazor.Themes -Version 29.1.33
NOTE
Ensure that the package
Microsoft.AspNetCore.Components.WebView.WindowsForms
updated to version8.0.16
.
NOTE
Syncfusion® Blazor components are available in nuget.org. Refer to NuGet packages topic for available NuGet packages list with component details.
Register Syncfusion® Blazor Service
Open ~/_Imports.razor file and import the Syncfusion.Blazor
and Syncfusion.Blazor.Calendars
namespace.
@using Syncfusion.Blazor
@using Syncfusion.Blazor.Calendars
Now, register the Syncfusion® Blazor service in the Form1.cs
file of your WinForms Blazor App.
using Syncfusion.Blazor;
....
service.AddSyncfusionBlazor();
....
Add stylesheet and script resources
The theme stylesheet and script can be accessed from NuGet through Static Web Assets. Reference the stylesheet and script in the <head>
of the ~wwwroot/index.html file.
<head>
....
<link href="_content/Syncfusion.Blazor.Themes/bootstrap5.css" rel="stylesheet" />
<script src="_content/Syncfusion.Blazor.Core/scripts/syncfusion-blazor.min.js" type="text/javascript"></script>
</head>
NOTE
Check out the Blazor Themes topic to discover various methods (Static Web Assets, CDN, and CRG) for referencing themes in your Blazor application. Also, check out the Adding Script Reference topic to learn different approaches for adding script references in your Blazor application.
Add Syncfusion® Blazor component
Now add Syncfusion® Blazor component in any razor file. Here, the Calendar component is added in ~/Counter.razor
.
<SfCalendar TValue="DateTime"></SfCalendar>
In the Visual Studio toolbar, select the start button to build and run the app.