0

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

Cfun
  • 8,442
  • 4
  • 30
  • 62
RL89
  • 1,866
  • 5
  • 22
  • 39
  • I'd guess this is an issue with the scanner or its drivers, not your code – Jason Feb 03 '21 at 14:00
  • The scanner works fine if I use it a notepad. Dont think there is a issue with the scanner – RL89 Feb 03 '21 at 14:08
  • are you clearing all the existing values when you navigate to the page the 2nd time? – Jason Feb 03 '21 at 14:10
  • Yes I do. But if that was the case, dont you think the whole value would get append or prepend and not just a single digit? – RL89 Feb 03 '21 at 14:29

0 Answers0