Here we will provide a step-by-step guide how to build a .NET MAUI app with barcode generation feature enabled. It is a simple MAUI app which allows user to
enter Code 128 barcode text and print barcode on the MAUI view.
After finish the tutorial, you can also further customize the C# code to add more barcode options, such as generating styled QR Code with logo image inside.
Here we will quickly create a new .NET MAUI app using Visual Studio.
Launch Visual Studio 2026 and choose Create a new project.
Find and choose .NET MAUI Blazor Hybrid App template; and then click Next button.
Use project name BarcodeLib.CsharpBarcodeGenerator.MAUI.Demo for this demo.
On the Additional information screen, choose target framework .NET 10.0, and then click Create.
Now, all template auto-generated contents would be listed in the Solution Explorer.
2. Install Barcode Generator library and Nuget package
Now we will add and install BarcodeLib C# barcode generator library (dll file) to the new .NET MAUI project
and also add the a Nuget package named "SkiaSharp".
Add BarcodeLib C# Barcode Generator library
Right-click Dependencies in the Solution Explorer, and click Manage NuGet Packages....
Find package SkiaSharp in the NuGet Package Manager and install the package.
Note: BarcodeLib.Barcode.SkiaSharp.dll requires SkiaSharp Version 2.80.0 or later.
Add required library BarcodeLib.Barcode.SkiaSharp.dll to the project.
Ensure required libraries have been added to this project successfully.
Design the user interface
Step 1: click App.xaml.cs in the Solution Explorer and change start window's title and size.
An input text element for inputting data message.
Set width to 360 pixels.
A Button for refreshing the barcode image.
Set attribute value to Refresh.
An Image for showing the barcode.
Set the width to 360 pixels.
4. Add C# codes to controls event handler
Step 1: Right-click Home.razor and choose Add Home.razor.cs to create a file Home.razor.cs.
Step 2: replace all contents in the Home.razor.cs file by the following C# codes.
usingBarcodeLib.Barcode;
usingSkiaSharp;
namespaceBarcodeLib.CsharpBarcodeGenerator.MAUI.Demo.Components.Pages
{
publicpartialclassHome
{
// Barcode message.protectedstring?Message { get; set; } ="Code 128";
// Barcode image in string format with encoding Base64.protectedstring?BarcodeImage { get; set; }
protectedoverridevoidOnInitialized()
{
// Show default barcode image.refreshBarcodeImage();
}
// Define the Handler in Code-BehindprivateasyncTaskRefreshBarcodeImage()
{
// Show current barcode image.refreshBarcodeImage();
StateHasChanged();
}
// Refresh barcode image.privatevoidrefreshBarcodeImage()
{
// Create a new Code 128 barcodeLinearlinear=newLinear();
linear.Type=BarcodeType.CODE128;
// Set data to the current content in the input (text).linear.Data=this.Message;
// Draw barcode to SKBitmap and convert to byte array.SKBitmapbitmap=linear.drawBarcode();
SKDatadata=bitmap.Encode(SKEncodedImageFormat.Png, 100);
varbytes=data.ToArray();
// Encode image data bytes to string with Base64.this.BarcodeImage=$"data:image/png;base64,{Convert.ToBase64String(bytes)}";
}
}
}
Binding code-behind to HTML elements
Step 1: establish a two-way data binding connection that synchronizes the attribute value of the HTML <input> text element directly with the property Message.