Reputation: 1190
I have barcode scanner. I need to capture string from barcode into textbox. The final word in textbox will be composed of multiple codes from barcode scanner. What event(s) should I use?
For example :
Barcode sends value 123
.
I tried PreviewTextInput
event and e.Text
but it captured only first char 1
. How can I get all added chars to textbox when I use barcode scanner?
Upvotes: 1
Views: 1753
Reputation: 3333
TextBox does not lose anything. If e.Text
is "1"
then it only means that your scanner sends characters to TextBox
one by one. Meaning you will get one event per character added.
Your approach is really wierd tho. TextBox
knows nothing about barcodes, scanners. etc. It simply displays text. Why do you ask it, if your scanner finished scanning? That makes no sense. Leave poor TextBox
alone. If you want to know when the scanning procces is finished, than you should add an appropriate event to class, which actually reads barcodes. And then, after this event fires, you should access the resulting string via TextBox.Text
or using other means (forexample by accessing a viewmodel property).
Edit: the thing with wpf events, is that your control needs to have "keyboard focus", if you want it to recieve keyboard events. If you show a MessageBox
then your TextBox
loses focus and, as a result, no longer recieves events. Again, leave the TextBox
alone. You need to write a dedicated class (i.e. BarcodeReader
) which will handle keyboard events for you and then fire an event when the barcode is read. You can use Keyboard class inside the BarcodeReader
to handle buttons pressed.
Upvotes: 2
Reputation: 470
If you are using C# in back end then you can have a look at this question: Reading bar codes using wpf application
Upvotes: 1