I have a mobile app written in Xamarin.Forms. I am scanning a barcode which is attached to the mobile through USB. I am not using any sdk to read the barcode instead I have a focus on a textbox as soon as the user opens the scanning page.
The generated barcode has a trailing space in it which helps to identify when the barcode input has finished. Hence I have written the below code to fire my backend service when that happens.
private void BarcodeNumber_TextChanged(object sender, TextChangedEventArgs e)
{
if(e.NewTextValue.EndsWith(" "))
{
ExecuteSearchBarcodeNumberCommand(e.NewTextValue.TrimEnd());
}
}
The above scenario is working fine but I have observed an intermittent behavior with the TextChanged
event.
Issue user case:
- Go to barcode scanner page -> scan the barcode -> it populates the number with the correct barcode number
- After this, if I go to any other page -> and come back to scanner page -> scan same barcode again -> it is prepending first digit of the number in the textbox.
For example the barcode number is 54321.
In the second case it prepend 5 in the number and lookup the service with 554321.
Thanks in advance