How to Build a QR Code Scanner in WPF
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.
How to Scan a QR Code in WPF
- Install the IronQR C# library via NuGet
- Add a
ButtonandTextBlockto the WPF window in XAML - Open a file dialog with
OpenFileDialogto select an image from disk - Load the image with
AnyBitmap.FromFileand wrap it in aQrImageInput - Call
Readand display the decoded value in theTextBlock
Prerequisites
- Visual Studio 2022 with the .NET desktop development workload installed
- 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:
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>
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 - 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.";
}Imports IronQr
Imports IronSoftware.Drawing
Imports Microsoft.Win32
Imports System.Windows
Private Sub OnScanButtonClicked(sender As Object, e As RoutedEventArgs)
' Open a file dialog to select a QR code image
Dim dialog As New OpenFileDialog With {
.Title = "Select a QR code image",
.Filter = "Image Files|*.png;*.jpg;*.jpeg;*.bmp;*.gif;*.tiff"
}
If dialog.ShowDialog() <> True Then Return
Dim imageSource As String = dialog.FileName
' Load the image into IronQR
Dim inputBmp As AnyBitmap = AnyBitmap.FromFile(imageSource)
' Load the asset into QrImageInput
Dim imageInput As New QrImageInput(inputBmp)
' Create a QR Reader object
Dim reader As New QrReader()
' Read the input and get all embedded QR Codes
Dim results As IEnumerable(Of QrResult) = reader.Read(imageInput)
' Display the first result
Dim firstResult As QrResult = results.FirstOrDefault()
ResultLabel.Text = If(firstResult IsNot Nothing, "Scanned Text: " & firstResult.Value, "No QR code found in the selected image.")
End SubOpenFileDialog 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.

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 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.