I'm developing a .NET MAUI app where I'm facing a problem: The Entry completed event doesn't trigger when I scan a barcode on Android, although it works on Windows. My barcode scanner is set up to send a carriage return (not an Enter key) after each scan, which should trigger the completed event.
<Entry x:Name="barcodeEntry" Placeholder="Scan barcode here" Completed="OnBarcodeCompleted" />
private void OnBarcodeCompleted(object sender, EventArgs e)
{
// Handle the barcode
}
This setup works as expected on Windows, but on Android, the completed event does not fire after scanning. I've confirmed the scanner sends a carriage return at the end of each scan and tested on multiple android devices, but the problem remains.
Has anyone else experienced this or can offer some insights into what might be going wrong or how to resolve this issue?
I'll propose a different approach to achieve what you need and then try to come with some possible explanation for the platform differences.
Alternative solution
You can bind to the Barcode text and process text changes yourself:
View:
ViewModel:
In this example I'm using MVVM Toolkit.
If you don't want to use MVVM Toolkit, you can use TextChanged event and further process the input:
Why is this happening?
From the docs:
From the source code, this is the Android condition to fire Completed event:
WPF condition:
On WPF, it seems that the '\r' character is associated with Key.Enter. So maybe this is where the difference comes from.