A barcode contains information about a product or a company, visually represented in a machine-readable form. Barcodes are widely used to track shipments and inventory management. We can easily generate various types of barcodes in WPF applications. In this article, we will learn how to generate and display a barcode image in the WPF application. After following the mentioned steps, we will have our own WPF Barcode Generator in C#. So let’s begin.
The article shall cover the following topics:
- Features of WPF Barcode Generator
- C# Barcode Generator API
- Steps to Create WPF Barcode Generator
- Generate Barcode with Additional Options
- Demo WPF Barcode Generator
- Download Source Code
Features of WPF Barcode Generator
Our WPF barcode generator will have the following features.
- Generate the following types of barcode symbologies:
- Code128
- Code11
- Code39
- QR
- Datamatrix
- EAN13
- EAN8
- ITF14
- PDF417
- Save the generated barcode image in the following formats:
- Preview the generated barcode image.
C# Barcode Generator API
We will be using the Aspose.BarCode for .NET API to generate barcode images and preview them in the WPF application. It is a feature-rich API that lets you generate, scan, and read a wide range of barcode types. Moreover, it allows to manipulate the appearance of the generated barcodes such as background color, bar color, rotation angle, x-dimension, image quality, resolution, captions, size and much more.
Steps to Create WPF Barcode Generator
We can generate and display a barcode image in the WPF application by following the steps given below:
- Firstly, create a new project and select the WPF Application project template.
Next, enter the name of the project e.g. “BarcodeGen”.
Then, select the .NET framework and then choose to create.
Next, open NuGet Package Manager and install Aspose.BarCode for .NET package.
- Then, add a new class Barcode.cs to define the barcode.
- Next, open the MainWindow.xaml and add the required controls as shown below:
You may also replace the content of MainWindow.xaml with the following script.
- Then, open the MainWindow.xaml.cs class and add btnGenerate_Click event to handle the click action for Generate Barcode button.
- After that, add a function to generate a barcode.
- Finally, run the application.
Generate Barcode with Additional Options
We can also generate barcodes with additional options specific to barcode types. In the WPF barcode generator, we have added a checkbox to generate a barcode with options. It will call the following function specifying additional options for different barcode types.
You may read more about Generation Specifics for Barcode Types in the documentation.
Demo WPF Barcode Generator
The following is the demonstration of the WPF Barcode Generator application that we have just created.
Download Source Code
You can download the complete source code of the WPF Barcode Generator application from GitHub.
Get a Free License
You can get a free temporary license to try the library without evaluation limitations.
Conclusion
In this article, we have learned how to generate various types of barcodes in a WPF application. We have also seen how to preview the generated barcode image programmatically. Besides, you can learn more about Aspose.BarCode for .NET API using the documentation. In case of any ambiguity, please feel free to contact us on our forum.