IRONSOFTWAREHOME

How to Build a QR Code Scanner in WPF

Curtis Chau
Curtis Chau
Updated: March 4, 2026

Windows Presentation Foundation (WPF) is a .NET framework for building Windows desktop applications with XAML-defined UIs. IronQR integrates directly into WPF, enabling QR code scanning from user-selected image files with just a few lines of C#.

In this guide, we'll build a WPF application that opens a file dialog, loads a selected image, and decodes any embedded QR code using IronQR. The approach supports PNG, JPEG, BMP, GIF, TIFF, and other common image formats.

Prerequisites

  1. Visual Studio 2022 with the .NET desktop development workload installed
  2. A WPF project targeting .NET 8 or later

Install IronQR

Install the IronQR library using the NuGet Package Manager Console in Visual Studio. Navigate to Tools > NuGet Package Manager > Package Manager Console and run:

PM > Install-Package IronQR

Alternatively, search for IronQR on NuGet and install the latest version.

WPF Window Layout

The scanner UI uses a Button to trigger the file dialog and a TextBlock to display the decoded result. Add the following markup to MainWindow.xaml:

<StackPanel Margin="28" VerticalAlignment="Center">

    <TextBlock Text="WPF QR Code Scanner" FontSize="20" FontWeight="Bold" Margin="0,0,0,16"/>

    <Button x:Name="ScanButton"
            Content="Select Image and Scan QR Code"
            Click="OnScanButtonClicked"
            Padding="12,8"
            Margin="0,0,0,16"
            HorizontalAlignment="Left"/>

    <TextBlock x:Name="ResultLabel"
               Text="Select an image to scan."
               TextWrapping="Wrap"
               FontSize="14"/>

</StackPanel>
XML

Sample Input

Use the QR code below as a test image. Save it to your device, select it through the file dialog, and click Select Image and Scan QR Code. The decoded value should display as https://ironsoftware.com.**

Sample QR code encoding https://ironsoftware.com for testing the WPF QR scanner

Sample QR code - encodes https://ironsoftware.com

QR Code Scanning with IronQR

When the button is clicked, OnScanButtonClicked opens a file dialog to select an image. The selected file is loaded into an AnyBitmap, passed to QrReader.Read, and the first decoded value is written to ResultLabel.

Add the following OnScanButtonClicked method to MainWindow.xaml.cs:

using IronQr;
using IronSoftware.Drawing;
using Microsoft.Win32;
using System.Windows;

private void OnScanButtonClicked(object sender, RoutedEventArgs e)
{
    // Open a file dialog to select a QR code image
    var dialog = new OpenFileDialog
    {
        Title = "Select a QR code image",
        Filter = "Image Files|*.png;*.jpg;*.jpeg;*.bmp;*.gif;*.tiff"
    };

    if (dialog.ShowDialog() != true) return;

    var imageSource = dialog.FileName;

    // Load the image into IronQR
    var inputBmp = AnyBitmap.FromFile(imageSource);

    // Load the asset into QrImageInput
    QrImageInput imageInput = new QrImageInput(inputBmp);

    // Create a QR Reader object
    QrReader reader = new QrReader();

    // Read the input and get all embedded QR Codes
    IEnumerable<QrResult> results = reader.Read(imageInput);

    // Display the first result
    var firstResult = results.FirstOrDefault();
    ResultLabel.Text = firstResult != null
        ? "Scanned Text: " + firstResult.Value
        : "No QR code found in the selected image.";
}

OpenFileDialog provides native Windows file selection filtered to common image formats. AnyBitmap.FromFile handles format decoding for PNG, JPEG, BMP, GIF, and TIFF inputs, while QrReader.Read returns an IEnumerable<QrResult> containing one entry per detected QR code. FirstOrDefault safely returns null when no QR code is found, avoiding exceptions on images without a valid code.

Output

After selecting a QR code image and clicking the scan button, the decoded value appears in the TextBlock below the button.

WPF QR Code Scanner using IronQR — decoded result displayed in the window

Decoded QR code value rendered in the WPF window

Download the Project

Click here to download the complete WpfQrScanner project.

Conclusion

IronQR integrates into a WPF application with minimal setup - a single QrReader.Read call handles the entire decoding pipeline on the desktop. To scan multiple QR codes from a single image, iterate over the full results collection instead of calling FirstOrDefault.

This same pattern extends to batch processing by looping through a directory of image files, or to real-time scanning by capturing frames from a webcam feed with a WPF media element.

For more on reading QR codes and the available scan modes, see the Read QR Codes from Image and Read QR Codes with Scan Modes guides.

Frequently Asked Questions

What is required to build a QR Code Scanner in WPF using IronQR?

To build a QR Code Scanner in WPF using IronQR, you need Visual Studio 2022 with the .NET desktop development workload installed and a WPF project targeting .NET 8 or later. Additionally, install IronQR via the NuGet Package Manager.

How can I start scanning QR codes using IronQR in WPF?

Start by installing the IronQR library via NuGet and adding a Button and TextBlock to your WPF window in XAML. Open a file dialog using OpenFileDialog to select an image and load it with AnyBitmap.FromFile, then call Read through QrReader to decode and display the QR code.

What image formats does IronQR support for QR code scanning in WPF?

IronQR supports various common image formats such as PNG, JPEG, BMP, GIF, and TIFF for QR code scanning in WPF applications.

How do I integrate IronQR into a WPF application?

Integrate IronQR into a WPF application by using NuGet to install the library and setting up your application UI with components like a Button to trigger image selection and a TextBlock for displaying results.

What happens if no QR code is found in an image?

If no QR code is found in the image, IronQR's Read method returns null, and you can display a message like 'No QR code found in the selected image' instead of a decoded result.

Can IronQR handle multiple QR codes in a single image?

Yes, IronQR can handle multiple QR codes in a single image. Iterate over the collection returned by QrReader.Read to access all detected QR codes, instead of using FirstOrDefault.

What are the key components in the WPF UI for a QR scanner using IronQR?

The key components in the WPF UI for a QR scanner using IronQR include a Button to trigger the file dialog, an OpenFileDialog for selecting images, and a TextBlock to display the decoded QR code result.

How is a file selected for QR code scanning in the WPF application?

A file is selected for QR code scanning in the WPF application using the OpenFileDialog, which allows users to pick an image file from disk, filtered to common image formats.

Is real-time QR code scanning possible with IronQR in WPF?

Yes, real-time QR code scanning is possible with IronQR in WPF by capturing frames from a webcam feed using a WPF media element and processing them with IronQR.

How do I display a decoded QR code value in the WPF application?

Display a decoded QR code value in the WPF application by assigning the result from QrReader.Read to a TextBlock component, showcasing the scanned text or URL.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...
Read More

Ready to Get Started?

Nuget Downloads 74,386Version:2026.9just released

Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronQR
nuget.org/packages/IronQR/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronQR"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

  1. Download and unzip IronQR to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronQR.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required