Getting Started with WPF Blazor Application
27 Feb 20243 minutes to read
This section explains how to create and run the first WPF Blazor App UI (.NET WPF Blazor) app with Syncfusion Blazor components.
What is WPF Blazor App?
WPF Blazor App is an app where Blazor web app
is hosted in WPF 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 WPF 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. WPF Blazor apps can run on all the platforms supported by WPF.
Visual Studio provides WPF Application template to create WPF Blazor Apps.
Prerequisites
-
Visual Studio 2022 with the .NET desktop development workload
Create a new WPF Blazor App in Visual Studio
You can create a WPF Blazor App using Visual Studio via Microsoft Templates
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 27.1.48
Install-Package Syncfusion.Blazor.Themes -Version 27.1.48
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 MainWindow.xaml.cs
file of your WPF Blazor App.
using Syncfusion.Blazor;
....
serviceCollection.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.
NOTE
Download demo from GitHub