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:
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>
<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:
:path=/static-assets/qr/content-code-examples/get-started/wpf-qr-code-scanner.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 Sub
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.
Decoded QR code value rendered in the WPF window
Download the 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.

