Skip to footer content

How to Read & Scan Barcode in C# Using NET MAUI

This tutorial demonstrates how to create a barcode scanning app using .NET MAUI and IronBarcode. The process begins with setting up a .NET MAUI cross-platform application in Visual Studio, ensuring the necessary development workload is installed. Next, the IronBarcode library is integrated via the NuGet package manager. The user interface is created using XAML, featuring a scrollable view, a vertical stack layout, and interactive elements such as buttons and an image tag. The main functionality is implemented in C#, where methods handle image selection, barcode scanning, and text copying to the clipboard. Users can select an image containing a barcode, scan it with IronBarcode, and display the decoded text efficiently. The app supports various barcode types, showcasing its versatility. This guide provides a comprehensive walkthrough of building a barcode scanner app, highlighting the integration of IronBarcode with .NET MAUI. Explore more possibilities with IronBarcode and enhance your app development experience.

<!-- XAML for User Interface -->
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="BarcodeScannerApp.MainPage">
    <ScrollView>
        <VerticalStackLayout Padding="10">
            <Button Text="Select Image" Clicked="OnSelectImageClicked"/>
            <Image x:Name="SelectedImage" HeightRequest="200"/>
            <Button Text="Scan Barcode" Clicked="OnScanBarcodeClicked"/>
            <Label x:Name="DecodedTextLabel" Text="Decoded text will appear here."/>
            <Button Text="Copy to Clipboard" Clicked="OnCopyToClipboardClicked"/>
        </VerticalStackLayout>
    </ScrollView>
</ContentPage>
<!-- XAML for User Interface -->
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="BarcodeScannerApp.MainPage">
    <ScrollView>
        <VerticalStackLayout Padding="10">
            <Button Text="Select Image" Clicked="OnSelectImageClicked"/>
            <Image x:Name="SelectedImage" HeightRequest="200"/>
            <Button Text="Scan Barcode" Clicked="OnScanBarcodeClicked"/>
            <Label x:Name="DecodedTextLabel" Text="Decoded text will appear here."/>
            <Button Text="Copy to Clipboard" Clicked="OnCopyToClipboardClicked"/>
        </VerticalStackLayout>
    </ScrollView>
</ContentPage>
XML

Further Reading: .NET MAUI Barcode Scanner

Jordi Bardia
Software Engineer
Jordi is most proficient in Python, C# and C++, when he isn’t leveraging his skills at Iron Software; he’s game programming. Sharing responsibilities for product testing, product development and research, Jordi adds immense value to continual product improvement. The varied experience keeps him challenged and engaged, and he says it’s one of his favorite aspects of working with Iron Software. Jordi grew up in Miami, Florida and studied Computer Science and Statistics at University of Florida.