In this article, we will explore the integration of Stimulsoft into WinUI projects.
WinUI is a user interface (UI) framework for Windows desktop applications, including managed applications using C# and .NET, as well as native applications using C++ with the Win32 API. WinUI 3 provides a consistent, intuitive, and accessible experience using the latest UI patterns. There is no dedicated Stimulsoft solution for WinUI; however, to embed a reporting system, you can use the Stimulsoft.Reports.Web.NetCore component, and if analytical systems need to be integrated, the Stimulsoft.Dashboards.Web.NetCore component can be used. Important!
The reporting tool for .NET Core allows you to create reports of any complexity, from standard invoices to complex documents with parameters, interactive sorting, and drill-down capabilities. However, native visual components, the report viewer, and the report designer for the WinUI framework are not available, and components from .NET Core packages may behave unpredictably. This is due to certain characteristics of the WinUI framework itself. Therefore, at this time, we don’t recommend embedding the viewer or designer into WinUI projects. At the same time, a report can still be generated and displayed as an exported result, such as a PDF file or HTML. The Windows App SDK C# Templates package must be installed beforehand. In the Visual Studio installer, this SDK is located under the .NET Desktop Development category.
To make the file accessible, set its "Build Action" property to "Embedded resource".
MainWindow.xaml
MainWindow.xaml.cs
Thus, when developing Blank App, Packaged (WinUI 3 in Desktop) applications, reporting and data analytics systems can be used without integrating the report viewer or designer. More details on using .NET Core Stimulsoft can be found in the documentation. The activation of Stimulsoft.Reports.Web.NetCore is available with the Reports.WEB subscription, while Stimulsoft.Dashboards.Web.NetCore requires the Dashboards.WEB subscription. Additionally, a comprehensive solution for reporting and analytics across multiple platforms Stimulsoft Ultimate can be purchased in the online store.
The reporting tool for .NET Core allows you to create reports of any complexity, from standard invoices to complex documents with parameters, interactive sorting, and drill-down capabilities. However, native visual components, the report viewer, and the report designer for the WinUI framework are not available, and components from .NET Core packages may behave unpredictably. This is due to certain characteristics of the WinUI framework itself. Therefore, at this time, we don’t recommend embedding the viewer or designer into WinUI projects. At the same time, a report can still be generated and displayed as an exported result, such as a PDF file or HTML. The Windows App SDK C# Templates package must be installed beforehand. In the Visual Studio installer, this SDK is located under the .NET Desktop Development category.
Step 1
First, create and initialize a new WinUI project – Blank App, Packaged (WinUI 3 in Desktop).Step 2
When creating a Blank App, Packaged (WinUI 3 in Desktop), it already includes a demo project where we will integrate our tools. First, install the required NuGet package into this demo project: Stimulsoft.Reports.Web.NetCore for reporting, or Stimulsoft.Dashboards.Web.NetCore if data analytics is also needed.Step 3
Add report files to the project. These can be report or dashboard templates (`*.mrt, *.mrz, *.mrx`), as well as generated report files (`*.mdc, *.mdz, *.mdx`). For example, add the Invoice.mrt report template to the Assets folder. Note!To make the file accessible, set its "Build Action" property to "Embedded resource".
Step 4
Next, in the MainWindow.xaml file, add the markup for displaying WebView2:MainWindow.xaml
<?xml version="1.0" encoding="utf-8"?>
<Window
x:Class="App1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="App1">
<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="100" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button x:Name="button" HorizontalAlignment="Center" VerticalAlignment="Center"
Content="Click To Show Report"
Click="Button_Click" />
<WebView2 x:Name="webView" Grid.Row="1" />>
</Grid>
</Window>
Step 5
At this step, add the code to the MainWindow.xaml.cs file to load and display the report in WebView2 when handling the "button click" event:MainWindow.xaml.cs
using System;
using System.IO;
using System.Reflection;
using Microsoft.UI.Xaml;
using Stimulsoft.Report;
using Stimulsoft.Report.Export;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
namespace App1
{
/// <summary>
/// An empty window that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainWindow : Window
{
public MainWindow()
{
this.InitializeComponent();
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
button.Content = "Clicked";
// Load the report
var report = new StiReport();
var reportStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("App1.Assets.Christmas.mrt");
report.Load(reportStream);
// Export the report to PDF
report.Render();
using var pdfStream = new MemoryStream();
report.ExportDocument(StiExportFormat.Pdf, pdfStream, new StiPdfExportSettings());
var pdfString = Convert.ToBase64String(pdfStream.ToArray());
await webView.EnsureCoreWebView2Async();
// Display the PDF in a WebView2 control
webView.NavigateToString(
@$"<html><head></head><body><div><object type=""application/pdf"" width=""100%"" height=""100%"" data=""data:application/pdf;base64,{pdfString}""></object></div></body></html>");
}
}
}

Thus, when developing Blank App, Packaged (WinUI 3 in Desktop) applications, reporting and data analytics systems can be used without integrating the report viewer or designer. More details on using .NET Core Stimulsoft can be found in the documentation. The activation of Stimulsoft.Reports.Web.NetCore is available with the Reports.WEB subscription, while Stimulsoft.Dashboards.Web.NetCore requires the Dashboards.WEB subscription. Additionally, a comprehensive solution for reporting and analytics across multiple platforms Stimulsoft Ultimate can be purchased in the online store.